Repository: zulip/zulip
Pull request: hotkey: Disable left arrow hotkey when view has unreads.
On pressing left arrow key while in narrow stream to edit
the last message, if the user has unread messages sent in
topics other than the one where the user has sent its last
message (considering the topics for same stream) and the unread
messages were sent before the user message, the hotkey unexpectedly
marks the messages as read. Hence we disable the hotkey for
such a case.
Fixes #17737.

<!-- What's this PR for?  (Just a link to an issue is fine.) -->


**Testing plan:** <!-- How have you tested? -->


**GIFs or screenshots:** <!-- If a UI change.  See:
  https://zulip.readthedocs.io/en/latest/tutorials/screenshot-and-gif-software.html
  -->


<!-- Also be sure to make clear, coherent commits:
  https://zulip.readthedocs.io/en/latest/contributing/version-control.html
  -->


Problem statement:
Edit last message keyboard shortcut (←) may unexpectedly mark many messages read
If you write a message in a narrowed view, then go back to an unnarrowed view, there may now be many unread messages between your new current position and the message you just wrote. If you then accidentally press `←`, all of those messages will be marked read unexpectedly, causing you to lose your place while catching up.

We should either
* disable the `←` shortcut if there are unread messages between your current position and the message to be edited, or
* disable the `←` shortcut if you’ve switched views since writing the last message.

Hints from issue discussion:
Hello @zulip/server-message-view members, this issue was labeled with the "area: message-editing" label, so you may want to check it out!

<!-- areaLabelAddition -->
Hello @andersk I wanna work on this issue
I think this option makes sense to me, probably with a notice:
> disable the ← shortcut if there are unread messages between your current position and the message to be edited, or

@zulipbot claim
Hello @ligmitz, you claimed this issue to work on it, but this issue and any referenced pull requests haven't been updated for 10 days. Are you still working on this issue?

If so, please update this issue by leaving a comment on this issue to let me know that you're still working on it. Otherwise, I'll automatically remove you from this issue in 4 days.

If you've decided to work on something else, simply comment `@zulipbot abandon` so that someone else can claim it and continue from where you left off.

Thank you for your valuable contributions to Zulip!

<!-- inactiveWarning -->

Commit message: message_edit: Remove incorrect `from_scroll` value.

Since it is important that the message being edited is visible,
it is safe to ignore `from_scroll` here which is also an
unlikely possibility here.

Patch to review:
diff --git a/web/src/message_edit.ts b/web/src/message_edit.ts
index 01a1d0ef49e25..fe78b813cee19 100644
--- a/web/src/message_edit.ts
+++ b/web/src/message_edit.ts
@@ -1272,7 +1272,7 @@ export function edit_last_sent_message(): void {
         return;
     }
 
-    message_lists.current.select_id(msg.id, {then_scroll: true, from_scroll: true});
+    message_lists.current.select_id(msg.id, {then_scroll: true});
 
     const $msg_row = message_lists.current.get_row(msg.id);
     if (!$msg_row) {


Code review comments:
diff_hunk: @@ -1252,6 +1252,30 @@ export function maybe_show_edit($row: JQuery, id: number): void {
     }
 }
 
+function warn_user_about_unread_msgs(last_sent_msg_id: number): void {
+    feedback_widget.show({
+        populate(container) {
+            container.html(
+                $t({
+                    defaultMessage:
+                        "Editing the last message you sent will mark all older messages in this view as read.",
+                }),
+            );
+        },
+        on_undo() {
+            // Select the message we want to edit to mark messages between it and the
+            // current selected id as read.
+            message_lists.current?.select_id(last_sent_msg_id, {
+                then_scroll: true,
+                from_scroll: true,
path: web/src/message_edit.ts
text: @user1:
I was trying to preserve the `select_id` parameters passed below, but yeah I see it not required even in the line after this, so I removed `from_scroll` from both the places.