mirror of https://github.com/zulip/zulip.git
Append space as needed in compose_ui.smart_insert().
This commit is contained in:
parent
f935afa241
commit
d7254a0556
|
@ -57,13 +57,22 @@ function make_textbox(s) {
|
|||
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.equal(textbox.insert_text, ':octopus: ');
|
||||
assert.equal(textbox.val(), ':octopus: abc :smile: :airplane:');
|
||||
assert(textbox.focused);
|
||||
|
||||
textbox.caret(textbox.val().length);
|
||||
textbox.blur();
|
||||
compose_ui.smart_insert(textbox, ':heart:');
|
||||
assert.equal(textbox.insert_text, ' :heart:');
|
||||
assert.equal(textbox.val(), ':octopus: abc :smile: :airplane: :heart:');
|
||||
assert(textbox.focused);
|
||||
|
||||
// Note that we don't have any special logic for strings that are
|
||||
// already surrounded by spaces, since we are usually inserting things
|
||||
// like emojis and file links.
|
||||
}());
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ exports.smart_insert = function (textarea, syntax) {
|
|||
|
||||
var pos = textarea.caret();
|
||||
var before_str = textarea.val().slice(0, pos);
|
||||
|
||||
var after_str = textarea.val().slice(pos);
|
||||
|
||||
if (pos > 0) {
|
||||
if (!is_space(before_str.slice(-1))) {
|
||||
|
@ -21,6 +21,12 @@ exports.smart_insert = function (textarea, syntax) {
|
|||
}
|
||||
}
|
||||
|
||||
if (after_str.length > 0) {
|
||||
if (!is_space(after_str[0])) {
|
||||
syntax += ' ';
|
||||
}
|
||||
}
|
||||
|
||||
textarea.caret(syntax);
|
||||
textarea.focus();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue