diff --git a/config/settings.toml b/config/settings.toml index e5996e8e..c108e24f 100644 --- a/config/settings.toml +++ b/config/settings.toml @@ -16,3 +16,6 @@ cursor_style="line" word_wrap=false exclude_dirs=[".git"] exclude_types=["__pycache__"] + +[vim] +enabled=false diff --git a/src/biscuit/api/commands.py b/src/biscuit/api/commands.py index 53ae006c..0a0e358a 100644 --- a/src/biscuit/api/commands.py +++ b/src/biscuit/api/commands.py @@ -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""" diff --git a/src/biscuit/commands.py b/src/biscuit/commands.py index c003a6d7..950e21c9 100644 --- a/src/biscuit/commands.py +++ b/src/biscuit/commands.py @@ -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() diff --git a/src/biscuit/editor/misc/welcome.py b/src/biscuit/editor/misc/welcome.py index 07ec316e..b42fc0de 100644 --- a/src/biscuit/editor/misc/welcome.py +++ b/src/biscuit/editor/misc/welcome.py @@ -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, diff --git a/src/biscuit/layout/statusbar/statusbar.py b/src/biscuit/layout/statusbar/statusbar.py index d9237688..1074ad52 100644 --- a/src/biscuit/layout/statusbar/statusbar.py +++ b/src/biscuit/layout/statusbar/statusbar.py @@ -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="", @@ -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)