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,13 +57,22 @@ function make_textbox(s) {
 | 
				
			|||||||
    assert.equal(textbox.val(), 'abc :smile: :airplane:');
 | 
					    assert.equal(textbox.val(), 'abc :smile: :airplane:');
 | 
				
			||||||
    assert(textbox.focused);
 | 
					    assert(textbox.focused);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test the current slightly-broken behavior.
 | 
					 | 
				
			||||||
    textbox.caret(0);
 | 
					    textbox.caret(0);
 | 
				
			||||||
    textbox.blur();
 | 
					    textbox.blur();
 | 
				
			||||||
    compose_ui.smart_insert(textbox, ':octopus:');
 | 
					    compose_ui.smart_insert(textbox, ':octopus:');
 | 
				
			||||||
    assert.equal(textbox.insert_text, ':octopus:');
 | 
					    assert.equal(textbox.insert_text, ':octopus: ');
 | 
				
			||||||
    assert.equal(textbox.val(), ':octopus:abc :smile: :airplane:');
 | 
					    assert.equal(textbox.val(), ':octopus: abc :smile: :airplane:');
 | 
				
			||||||
    assert(textbox.focused);
 | 
					    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 pos = textarea.caret();
 | 
				
			||||||
    var before_str = textarea.val().slice(0, pos);
 | 
					    var before_str = textarea.val().slice(0, pos);
 | 
				
			||||||
 | 
					    var after_str = textarea.val().slice(pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pos > 0) {
 | 
					    if (pos > 0) {
 | 
				
			||||||
        if (!is_space(before_str.slice(-1))) {
 | 
					        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.caret(syntax);
 | 
				
			||||||
    textarea.focus();
 | 
					    textarea.focus();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user