Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_box: Render limit indicator as template with zero-width space.
Karl Stolley4fee51fc9978
diff --git a/web/src/compose_validate.js b/web/src/compose_validate.jsindex 31a11d43799..5289383d915 100644--- a/web/src/compose_validate.js+++ b/web/src/compose_validate.js@@ -5,6 +5,7 @@ import render_compose_banner from "../templates/compose_banner/compose_banner.hbimport render_not_subscribed_warning from "../templates/compose_banner/not_subscribed_warning.hbs";import render_private_stream_warning from "../templates/compose_banner/private_stream_warning.hbs";import render_wildcard_warning from "../templates/compose_banner/wildcard_warning.hbs";+import render_compose_limit_indicator from "../templates/compose_limit_indicator.hbs";import * as channel from "./channel";import * as compose_banner from "./compose_banner";@@ -624,7 +625,12 @@ export function check_overflow_text() {if (text.length > max_length) {$indicator.addClass("over_limit");$("textarea#compose-textarea").addClass("over_limit");- $indicator.text(text.length + "/" + max_length);+ $indicator.html(+ render_compose_limit_indicator({+ text_length: text.length,+ max_length,+ }),+ );compose_banner.show_error_message($t({@@ -640,8 +646,12 @@ export function check_overflow_text() {} else if (text.length > 0.9 * max_length) {$indicator.removeClass("over_limit");$("textarea#compose-textarea").removeClass("over_limit");- $indicator.text(text.length + "/" + max_length);-+ $indicator.html(+ render_compose_limit_indicator({+ text_length: text.length,+ max_length,+ }),+ );$("#compose-send-button").prop("disabled", false);$(`#compose_banners .${CSS.escape(compose_banner.CLASSNAMES.message_too_long)}`).remove();} else {diff --git a/web/templates/compose_limit_indicator.hbs b/web/templates/compose_limit_indicator.hbsnew file mode 100644index 00000000000..6fe0baf92bc--- /dev/null+++ b/web/templates/compose_limit_indicator.hbs@@ -0,0 +1,2 @@+{{! Include a zero-width-space to allow breaks in narrow compose boxes. }}+{{text_length}}​/{{max_length}}diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.jsindex ab5708a0f08..caabe519407 100644--- a/web/tests/compose_validate.test.js+++ b/web/tests/compose_validate.test.js@@ -562,10 +562,14 @@ test_ui("test_check_overflow_text", ({mock_template}) => {});// Indicator should show red colored text+ let limit_indicator_html;+ mock_template("compose_limit_indicator.hbs", true, (_data, html) => {+ limit_indicator_html = html;+ });$textarea.val("a".repeat(10000 + 1));compose_validate.check_overflow_text();assert.ok($indicator.hasClass("over_limit"));- assert.equal($indicator.text(), "10001/10000");+ assert.equal(limit_indicator_html, "10001​/10000\n");assert.ok($textarea.hasClass("over_limit"));assert.ok(banner_rendered);assert.ok($send_button.prop("disabled"));@@ -575,7 +579,7 @@ test_ui("test_check_overflow_text", ({mock_template}) => {$textarea.val("a".repeat(9000 + 1));compose_validate.check_overflow_text();assert.ok(!$indicator.hasClass("over_limit"));- assert.equal($indicator.text(), "9001/10000");+ assert.equal(limit_indicator_html, "9001​/10000\n");assert.ok(!$textarea.hasClass("over_limit"));assert.ok(!$send_button.prop("disabled"));assert.ok(!banner_rendered);