From bbd2b08b95d5ba41d80017b61703bfb11bf629fb Mon Sep 17 00:00:00 2001 From: vyshnav-vinod Date: Mon, 18 Mar 2024 14:51:50 +0530 Subject: [PATCH 1/2] Fix #244 Fixed issue causing a new tab to be opened when selecting a file who already has a tab opened #244 --- .../core/layout/base/content/editors/__init__.py | 14 +++++++++----- biscuit/core/layout/base/content/editors/tabs.py | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/biscuit/core/layout/base/content/editors/__init__.py b/biscuit/core/layout/base/content/editors/__init__.py index 0a1fd311..46aed831 100644 --- a/biscuit/core/layout/base/content/editors/__init__.py +++ b/biscuit/core/layout/base/content/editors/__init__.py @@ -83,11 +83,15 @@ def add_editors(self, editors: list[Editor]) -> None: def add_editor(self, editor: Union[Editor,BaseEditor]) -> Editor | BaseEditor: "Appends a editor to list. Create a tab." - self.active_editors.append(editor) - if editor.content: - editor.content.create_buttons(self.editorsbar.container) - self.tabs.add_tab(editor) - self.refresh() + if self.is_open(editor.path): + self.tabs.switch_tabs(editor=editor) + self.refresh() + else: + self.active_editors.append(editor) + if editor.content: + editor.content.create_buttons(self.editorsbar.container) + self.tabs.add_tab(editor) + self.refresh() return editor def delete_all_editors(self) -> None: diff --git a/biscuit/core/layout/base/content/editors/tabs.py b/biscuit/core/layout/base/content/editors/tabs.py index 8a907edb..c1392783 100644 --- a/biscuit/core/layout/base/content/editors/tabs.py +++ b/biscuit/core/layout/base/content/editors/tabs.py @@ -74,3 +74,8 @@ def clear_all_tabs(self) -> None: tab.destroy() self.tabs.clear() + + def switch_tabs(self, editor) -> None: + for tab in self.tabs: + if tab.editor.path == editor.path: + tab.select() From cb1f30f79797124f2390345c8f9b6a3350850a82 Mon Sep 17 00:00:00 2001 From: Billy Date: Tue, 19 Mar 2024 01:36:23 +0530 Subject: [PATCH 2/2] feat: Move checks to `open_editor` --- .../core/layout/base/content/editors/__init__.py | 16 +++++++--------- biscuit/core/layout/base/content/editors/tabs.py | 5 +++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/biscuit/core/layout/base/content/editors/__init__.py b/biscuit/core/layout/base/content/editors/__init__.py index 51d109f5..cd4508ef 100644 --- a/biscuit/core/layout/base/content/editors/__init__.py +++ b/biscuit/core/layout/base/content/editors/__init__.py @@ -84,15 +84,11 @@ def add_editors(self, editors: list[Editor]) -> None: def add_editor(self, editor: Union[Editor,BaseEditor]) -> Editor | BaseEditor: "Appends a editor to list. Create a tab." - if self.is_open(editor.path): - self.tabs.switch_tabs(editor=editor) - self.refresh() - else: - self.active_editors.append(editor) - if editor.content: - editor.content.create_buttons(self.editorsbar.container) - self.tabs.add_tab(editor) - self.refresh() + self.active_editors.append(editor) + if editor.content: + editor.content.create_buttons(self.editorsbar.container) + self.tabs.add_tab(editor) + self.refresh() return editor def delete_all_editors(self) -> None: @@ -126,6 +122,8 @@ def reopen_editor(self, path: str): def open_editor(self, path: str, exists: bool=True) -> Editor | BaseEditor: "open Editor with path and exists values passed" + if self.is_open(path): + return self.tabs.switch_tabs(path) if path in self.closed_editors: return self.add_editor(self.closed_editors[path]) return self.add_editor(Editor(self, path, exists)) diff --git a/biscuit/core/layout/base/content/editors/tabs.py b/biscuit/core/layout/base/content/editors/tabs.py index c1392783..885efaae 100644 --- a/biscuit/core/layout/base/content/editors/tabs.py +++ b/biscuit/core/layout/base/content/editors/tabs.py @@ -75,7 +75,8 @@ def clear_all_tabs(self) -> None: self.tabs.clear() - def switch_tabs(self, editor) -> None: + def switch_tabs(self, path) -> None: for tab in self.tabs: - if tab.editor.path == editor.path: + if tab.editor.path == path: tab.select() + return tab.editor