From 3539ebc76ee7725c14d4906dbfb5897d7629c831 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 21 May 2023 19:23:28 +0100 Subject: [PATCH 1/3] Ensure correct sidebar item is focused, or none, when tab removed --- src/MainWindow.vala | 9 ++++++++- src/Widgets/DocumentView.vala | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 57ded41e2..de3d30568 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -515,8 +515,15 @@ 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.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 123ca7c38..56f460ebc 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) => { From 2af803f53758ad71e8ec0f2a125027eb55d22ece Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 21 May 2023 19:37:45 +0100 Subject: [PATCH 2/3] Null check selected item --- src/MainWindow.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index de3d30568..639916a86 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -518,8 +518,8 @@ namespace Scratch { 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.file.file.equal (doc.file)) { + 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; } From 80baddc86ca10ed31fa48ce223a75c8d00a13dbb Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 21 May 2023 19:38:42 +0100 Subject: [PATCH 3/3] Fix whitespace --- src/MainWindow.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 639916a86..810e52387 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -523,7 +523,6 @@ namespace Scratch { // Do not leave removed tab selected folder_manager_view.selected = null; } - }); document_view.document_change.connect ((doc) => {