compose: Fix cursor position loss in quote-and-reply.

If you used "Quote and reply" to start composing a message, and
started typing before receiving the original message body from the
server, we ended up resetting your cursor to the start of the line
after the quote for two reasons:

* We were incorrectly fetching the pre_cursor for our replacement
  operation before doing the server fetch, which meant we ignored any
  editing done while waiting for the server to respond.

* Worse, we actually fetched the original cursor position before
  inserting the "[Quoting...]" placeholder text. So we were guaranteed
  to have at least some amount of error in the cursor position.

Fixes #20379.
This commit is contained in:
Tim Abbott 2021-11-27 20:25:01 -08:00 committed by Tim Abbott
parent 089fdc4d94
commit 25c9b05bd0
1 changed files with 1 additions and 2 deletions

View File

@ -482,8 +482,6 @@ export function quote_and_reply(opts) {
respond_to_message(opts); respond_to_message(opts);
} }
const prev_caret = textarea.caret();
compose_ui.insert_syntax_and_focus("[Quoting…]\n", textarea); compose_ui.insert_syntax_and_focus("[Quoting…]\n", textarea);
function replace_content(message) { function replace_content(message) {
@ -492,6 +490,7 @@ export function quote_and_reply(opts) {
// ```quote // ```quote
// message content // message content
// ``` // ```
const prev_caret = textarea.caret();
let content = $t( let content = $t(
{defaultMessage: "{username} [said]({link_to_message}):"}, {defaultMessage: "{username} [said]({link_to_message}):"},
{ {