[gnome-shell/gnome-41] messageList: Give focus to next message on delete



commit a89759a3ec33316124fc88f5a2e745d38fb2da93
Author: Dylan McCall <dylan dylanmccall ca>
Date:   Sun Nov 28 16:19:35 2021 -0800

    messageList: Give focus to next message on delete
    
    When the user deletes a message using the keyboard, set the keyboard
    focus to the next message, or to the list container itself, so it
    remains possible to navigate using the keyboard.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/502
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2053>
    (cherry picked from commit 4a23ddffa8094ef9bef9aefaef1eb23531d652de)

 js/ui/messageList.js | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/messageList.js b/js/ui/messageList.js
index 8ffdaebc13..77672a5928 100644
--- a/js/ui/messageList.js
+++ b/js/ui/messageList.js
@@ -663,12 +663,24 @@ var MessageListSection = GObject.registerClass({
     }
 
     removeMessage(message, animate) {
-        if (!this._messages.includes(message))
+        const messages = this._messages;
+
+        if (!messages.includes(message))
             throw new Error(`Impossible to remove untracked message`);
 
         let listItem = message.get_parent();
         listItem._connectionsIds.forEach(id => message.disconnect(id));
 
+        let nextMessage = null;
+
+        if (message.has_key_focus()) {
+            const index = messages.indexOf(message);
+            nextMessage =
+                messages[index + 1] ||
+                messages[index - 1] ||
+                this._list;
+        }
+
         if (animate) {
             listItem.ease({
                 scale_x: 0,
@@ -677,10 +689,12 @@ var MessageListSection = GObject.registerClass({
                 mode: Clutter.AnimationMode.EASE_OUT_QUAD,
                 onComplete: () => {
                     listItem.destroy();
+                    nextMessage?.grab_key_focus();
                 },
             });
         } else {
             listItem.destroy();
+            nextMessage?.grab_key_focus();
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]