mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Append space as needed in compose_ui.smart_insert().
This commit is contained in:
		@@ -57,7 +57,6 @@ 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:');
 | 
			
		||||
@@ -65,5 +64,15 @@ function make_textbox(s) {
 | 
			
		||||
    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();
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user