Skip to content

Commit

Permalink
Ensure correct sidebar item is focused, or none, when tab removed (#1320
Browse files Browse the repository at this point in the history
)

* Ensure correct sidebar item is focused, or none, when tab removed

* Null check selected item

* Fix whitespace

---------

Co-authored-by: Ryan Kornheisl <[email protected]>
  • Loading branch information
Jeremy Wootten and zeebok authored Jul 24, 2023
1 parent ca49df1 commit 26cdb9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 4 additions & 2 deletions src/Widgets/DocumentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 26cdb9e

Please sign in to comment.