Skip to content

Commit

Permalink
Add Vim mode to Biscuit
Browse files Browse the repository at this point in the history
Related to #405

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/tomlin7/biscuit/issues/405?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
tomlin7 committed Nov 3, 2024
1 parent 8bf062e commit 8fb13da
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ cursor_style="line"
word_wrap=false
exclude_dirs=[".git"]
exclude_types=["__pycache__"]

[vim]
enabled=false
3 changes: 3 additions & 0 deletions src/biscuit/api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def __init__(self, *a) -> None:

self.register_command = self.settings.register_command

# Register the toggle Vim mode command in the command palette
self.register_command("toggle_vim_mode", self.base.commands.toggle_vim_mode)

@property
def commands(self) -> None:
"""Return all registered commands"""
Expand Down
4 changes: 4 additions & 0 deletions src/biscuit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,7 @@ def view_biscuit_licenses(self, *_) -> None:
def show_about(self, *_) -> None:
messagebox.showinfo("Biscuit", str(self.base.system))
self.base.logger.info(str(self.base.system))

def toggle_vim_mode(self, *_) -> None:
self.base.settings.vim.enabled = not self.base.settings.vim.enabled
self.base.update_statusbar()
8 changes: 8 additions & 0 deletions src/biscuit/editor/misc/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def create_quick_group(self):
["Ctrl", "Shift", "X"],
).pack(fill=tk.X, expand=True)

QuickItem(
quick,
"Toggle Vim Mode",
Icons.KEYBOARD,
self.base.commands.toggle_vim_mode,
["Ctrl", "Shift", "V"],
).pack(fill=tk.X, expand=True)

def create_recent_group(self):
Label(
self.container,
Expand Down
18 changes: 18 additions & 0 deletions src/biscuit/layout/statusbar/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def __init__(self, master: Frame, *args, **kwargs) -> None:

self.panel_toggle.show()

# Add Vim mode indicators
self.vim_mode_indicator = self.add_button(
text="NORMAL",
callback=None,
description="Vim mode indicator",
side=tk.LEFT,
padx=(2, 0),
)
self.vim_mode_indicator.show()

def add_button(
self,
text="",
Expand Down Expand Up @@ -342,3 +352,11 @@ def change_language(self, language: str) -> typing.Callable:
return lambda _: self.base.editorsmanager.active_editor.content.text.highlighter.change_language(
language
)

def update_vim_mode_indicator(self, mode: str) -> None:
"""Updates the Vim mode indicator on the status bar.
Args:
mode (str): The current Vim mode.
"""
self.vim_mode_indicator.change_text(mode)

0 comments on commit 8fb13da

Please sign in to comment.