Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Restoring most recently closed tabs (#400) #401

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
593 changes: 360 additions & 233 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biscuit-editor"
version = "2.99.80"
version = "2.99.85"
description = "A lightweight, fast, and extensible code editor with a growing community"
authors = ["Billy <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/biscuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.99.80"
__version__ = "2.99.85"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

from .main import *
1 change: 1 addition & 0 deletions src/biscuit/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def bind_all(self) -> None:
self.bind(self.bindings.quit, self.events.quit_biscuit)
self.bind(self.bindings.undo, self.events.undo)
self.bind(self.bindings.redo, self.events.redo)
self.bind(self.bindings.restore_closed_tab, self.events.restore_last_closed_editor)

def late_bind_all(self) -> None:
"""Bindings that require full initialization"""
Expand Down
3 changes: 3 additions & 0 deletions src/biscuit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def open_recent_file(self, *_):

def open_recent_dir(self, *_):
self.base.palette.show("recentd:")

def restore_last_closed_editor(self, *_) -> None:
self.base.editorsmanager.restore_last_closed_editor()

def save_file(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
Expand Down
5 changes: 2 additions & 3 deletions src/biscuit/layout/editors/editorsbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def __init__(self, master: EditorsManager, *args, **kwargs) -> None:
self.tab_container.pack(fill=tk.BOTH, side=tk.LEFT)

self.menu = EditorsbarMenu(self.major_container, "tabs")
self.menu.add_command(
"Show Opened Editors", lambda: self.base.palette.show("active:")
)
self.menu.add_command("Show Opened Editors", lambda: self.base.palette.show("active:"))
self.menu.add_command("Restore Last Closed Editor", self.base.commands.restore_last_closed_editor)
self.menu.add_separator(10)
self.menu.add_command("Close All", self.master.delete_all_editors)

Expand Down
21 changes: 16 additions & 5 deletions src/biscuit/layout/editors/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, master: Content, *args, **kwargs) -> None:

self.active_editors: List[Editor] = []
self.closed_editors: Dict[Editor] = {}

self.closed_editors: List[Editor] = []
self.max_closed_editors = 10

self.emptytab = Placeholder(self)
self.emptytab.grid(column=0, row=1, sticky=tk.NSEW)
Expand Down Expand Up @@ -206,12 +209,20 @@ def close_editor(self, editor: Editor) -> None:
if editor.content and editor.content.editable:
self.base.language_server_manager.tab_closed(editor.content.text)

# not keeping diff/games in cache
if editor.content and not (editor.diff or editor.content.unsupported):
self.closed_editors[editor.path] = editor
else:
editor.destroy()
self.closed_editors.append(editor)
if len(self.closed_editors) > self.max_closed_editors:
oldest_editor = self.closed_editors.pop(0)
oldest_editor.destroy()

self.base.open_editors.remove_item(editor)

def restore_last_closed_editor(self) -> None:
if self.closed_editors:
editor = self.closed_editors.pop()
self.add_editor(editor)
# self.base.notifications.info(f"Restored {editor.filename}")
else:
self.base.notifications.info("No recently closed editors to restore")

def close_editor_by_path(self, path: str) -> None:
"""Closes the editor with the given path.
Expand Down
1 change: 1 addition & 0 deletions src/biscuit/settings/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ def __init__(self, master: Settings) -> None:
self.panel = "<Control-grave>"
self.undo = "<Control-z>"
self.redo = "<Control-y>"
self.restore_closed_tab = "<Control-Shift-T>"
Loading