compose: Fix extra space being added by quote-and-reply.

The correct behavior here is that we want to ensure there is
whitespace in between the syntax being added and the content on either
side.  Our smart_insert logic handled this for the cases that were
common with inserting emoji (etc.), but didn't handle the more complex
cases with "quote and reply".

Fixes #11702.
This commit is contained in:
Tim Abbott
2019-02-27 13:17:27 -08:00
parent 579e2e8b2b
commit f40cbdbd19
2 changed files with 33 additions and 2 deletions

View File

@@ -16,12 +16,18 @@ exports.smart_insert = function (textarea, syntax) {
var after_str = textarea.val().slice(pos);
if (pos > 0) {
if (!is_space(before_str.slice(-1))) {
// If there isn't space either at the end of the content
// before the insert or (unlikely) at the start of the syntax,
// add one.
if (!is_space(before_str.slice(-1)) && !is_space(syntax[0])) {
syntax = ' ' + syntax;
}
}
if (!(after_str.length > 0 && is_space(after_str[0]))) {
// If there isn't whitespace either at the end of the syntax or the
// start of the content after the syntax, add one.
if (!(after_str.length > 0 && is_space(after_str[0]) ||
syntax.length > 0 && is_space(syntax.slice(-1)))) {
syntax += ' ';
}