mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
Prepend space as needed in compose_ui.smart_insert().
This commit is contained in:
@@ -51,11 +51,18 @@ function make_textbox(s) {
|
||||
assert.equal(textbox.val(), 'abc :smile:');
|
||||
assert(textbox.focused);
|
||||
|
||||
// Test the current slightly-broken behavior.
|
||||
textbox.blur();
|
||||
compose_ui.smart_insert(textbox, ':airplane:');
|
||||
assert.equal(textbox.insert_text, ':airplane:');
|
||||
assert.equal(textbox.val(), 'abc :smile::airplane:');
|
||||
assert.equal(textbox.insert_text, ' :airplane:');
|
||||
assert.equal(textbox.val(), 'abc :smile: :airplane:');
|
||||
assert(textbox.focused);
|
||||
|
||||
// Test the current slightly-broken behavior.
|
||||
textbox.caret(0);
|
||||
textbox.blur();
|
||||
compose_ui.smart_insert(textbox, ':octopus:');
|
||||
assert.equal(textbox.insert_text, ':octopus:');
|
||||
assert.equal(textbox.val(), ':octopus:abc :smile: :airplane:');
|
||||
assert(textbox.focused);
|
||||
|
||||
}());
|
||||
|
||||
@@ -7,6 +7,20 @@ exports.autosize_textarea = function () {
|
||||
};
|
||||
|
||||
exports.smart_insert = function (textarea, syntax) {
|
||||
function is_space(c) {
|
||||
return (c === ' ') || (c === '\t') || (c === '\n');
|
||||
}
|
||||
|
||||
var pos = textarea.caret();
|
||||
var before_str = textarea.val().slice(0, pos);
|
||||
|
||||
|
||||
if (pos > 0) {
|
||||
if (!is_space(before_str.slice(-1))) {
|
||||
syntax = ' ' + syntax;
|
||||
}
|
||||
}
|
||||
|
||||
textarea.caret(syntax);
|
||||
textarea.focus();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user