mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
compose-box: Insert quoted content at the cursor position.
Right now, on clicking `quote and reply` on any message, the quoted message is always inserted at the top of compose-box irrespective of the current cursor position. Also, after insertion of the quoted message, the cursor is shifted at the end of the compose box. This commit changes this behaviour to insertion of quoted message at the current cursor position with a newline at the end of quote and moving the cursor position to that newline after insertion. A newline is added at the beginning of quoted message only if there was some content already present in compose box before the previous cursor position. Tested on Google Chrome and Firefox browsers on Ubuntu dev environment. Fixes: #16836
This commit is contained in:
committed by
Tim Abbott
parent
604f6c491c
commit
3294e8dbe0
@@ -458,21 +458,19 @@ export function quote_and_reply(opts) {
|
||||
// are prone to glitches where you select the
|
||||
// text, plus it's a complicated codepath that
|
||||
// can have other unintended consequences.)
|
||||
//
|
||||
// Note also that we always put the quoted text
|
||||
// above the current text, which explains us
|
||||
// moving the caret below. I think this is what
|
||||
// most users will want, and it's consistent with
|
||||
// the behavior we had on FF before this change
|
||||
// (which may have been an accident of
|
||||
// implementation). If we change this decision,
|
||||
// we'll need to make `insert_syntax_and_focus`
|
||||
// smarter about newlines.
|
||||
textarea.caret(0);
|
||||
|
||||
if (textarea.caret() !== 0) {
|
||||
// Insert a newline before quoted message if there is
|
||||
// already some content in the compose box and quoted
|
||||
// message is not being inserted at the beginning.
|
||||
textarea.caret("\n");
|
||||
}
|
||||
} else {
|
||||
respond_to_message(opts);
|
||||
}
|
||||
|
||||
const prev_caret = textarea.caret();
|
||||
|
||||
compose_ui.insert_syntax_and_focus("[Quoting…]\n", textarea);
|
||||
|
||||
function replace_content(message) {
|
||||
@@ -493,6 +491,8 @@ export function quote_and_reply(opts) {
|
||||
content += `${fence}quote\n${message.raw_content}\n${fence}`;
|
||||
compose_ui.replace_syntax("[Quoting…]", content, textarea);
|
||||
compose_ui.autosize_textarea($("#compose-textarea"));
|
||||
// Update textarea caret to point to the new line after quoted message.
|
||||
textarea.caret(prev_caret + content.length + 1);
|
||||
}
|
||||
|
||||
if (message && message.raw_content) {
|
||||
|
||||
Reference in New Issue
Block a user