Skip to content

Commit

Permalink
feat: Add block cursor (toggleable) #266
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 authored Mar 30, 2024
2 parents d269ec3 + 6918666 commit e288d59
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions biscuit/core/components/editors/texteditor/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ def __init__(self, master: TextEditor, path: str=None, exists: bool=True, minima
self.config_bindings()
self.update_idletasks()
tab_width = self.base.settings.font.measure(' ' * self.base.tab_spaces)
self.configure(tabs=(tab_width,), wrap=tk.NONE, relief=tk.FLAT, highlightthickness=0, bd=0, **self.base.theme.editors.text)
self.configure(tabs=(tab_width,), blockcursor=self.base.block_cursor, wrap=tk.NONE, relief=tk.FLAT, highlightthickness=0, bd=0, **self.base.theme.editors.text)

# modified event
self.clear_modified_flag()
self._user_edit = True
self._edit_stack = []
self._edit_stack_index = -1
self._last_selection: list[str, str] = [None, None]
self._last_cursor: list[str, str] = [None, None]

def config_tags(self):
self.tag_config(tk.SEL, background=self.base.theme.editors.selection)
Expand Down Expand Up @@ -558,6 +556,9 @@ def set_tab_size(self, size: int) -> None:
tab_width = self.base.settings.font.measure(' ' * size)
self.configure(tabs=(tab_width,))

def set_block_cursor(self, flag: bool) -> None:
self.configure(blockcursor=flag)

def get_cursor_pos(self):
return self.index(tk.INSERT)

Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/utils/iconlabelbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, master, text=None, icon=None, function=lambda *_: None, icons
self.icon = icon
self.codicon = get_codicon(self.icon)

self.toggle = True
self.toggle = toggle

if icon:
self.icon_label = tk.Label(self, text=self.codicon if self.toggle else " ", anchor=tk.E,
Expand Down
3 changes: 2 additions & 1 deletion biscuit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def setup_configs(self) -> None:
self.git_found = False
self.wrap_words = False
self.tab_spaces = 4
self.block_cursor = False
self.active_directory = None
self.active_branch_name = None
self.onupdate_callbacks = []
Expand Down Expand Up @@ -91,4 +92,4 @@ def set_tab_spaces(self, spaces: int) -> None:
if e := self.editorsmanager.active_editor:
if e.content and e.content.editable:
e.content.text.set_tab_size(spaces)
self.statusbar.set_spaces(spaces)
self.statusbar.set_spaces(spaces)
1 change: 1 addition & 0 deletions biscuit/core/layout/menubar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def add_edit_menu(self) -> None:
self.edit_menu.add_item("Change Language Mode", events.change_language_mode)
self.edit_menu.add_separator()
self.edit_menu.add_checkable("Word Wrap", events.toggle_wordwrap)
self.edit_menu.add_checkable("Block Cursor", events.toggle_block_cursor)

def add_selection_menu(self) -> None:
events = self.events
Expand Down
6 changes: 6 additions & 0 deletions biscuit/core/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ def toggle_wordwrap(self, *_) -> None:
if editor.content and editor.content.editable:
self.base.wrap_words = not self.base.wrap_words
editor.content.text.refresh_wrap()

def toggle_block_cursor(self, *_) -> None:
self.base.block_cursor = not self.base.block_cursor
if e := self.base.editorsmanager.active_editor:
if e.content and e.content.editable:
e.content.text.set_block_cursor(self.base.block_cursor)

def undo(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
Expand Down

0 comments on commit e288d59

Please sign in to comment.