From 26cdb9efbfe7ff88652b3c22aa4a0fdc299d3023 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 24 Jul 2023 04:04:31 +0100 Subject: [PATCH] Ensure correct sidebar item is focused, or none, when tab removed (#1320) * Ensure correct sidebar item is focused, or none, when tab removed * Null check selected item * Fix whitespace --------- Co-authored-by: Ryan Kornheisl --- src/MainWindow.vala | 8 +++++++- src/Widgets/DocumentView.vala | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index db444e8ff..d899b98c5 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -515,8 +515,14 @@ namespace Scratch { update_find_actions (); }); - document_view.tab_removed.connect (() => { + document_view.tab_removed.connect ((tab) => { update_find_actions (); + var doc = (Scratch.Services.Document)tab; + var selected_item = (Scratch.FolderManager.Item?)(folder_manager_view.selected); + if (selected_item != null && selected_item.file.file.equal (doc.file)) { + // Do not leave removed tab selected + folder_manager_view.selected = null; + } }); document_view.document_change.connect ((doc) => { diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index 80a4e6566..f76831259 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -79,8 +79,10 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { }); tab_switched.connect ((old_tab, new_tab) => { - /* The 'document_change' signal is emitted when the document is focused. We do not need to emit it here */ - save_focused_document_uri (new_tab as Services.Document); + var doc = (Services.Document)new_tab; + /* The 'document_change' signal may not be emitted if this already has focus so signal here*/ + document_change (doc, this); + save_focused_document_uri (doc); }); tab_restored.connect ((label, restore_data, icon) => {