Skip to content

Commit

Permalink
feat: skip insertion if expected closing bracket is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Mar 30, 2024
1 parent f6df8da commit 88e4329
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions biscuit/core/components/editors/texteditor/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ def close_bracket(self, e: tk.Event):
i -= 1
if stack[-1] == ch:
stack.pop()
if stack and stack[-1] == e.char:
if stack and stack[-1] == e.char:
# skip if next character is what we are closing
if c := self.get("insert", "insert+1c"):
if c == e.char:
self.mark_set(tk.INSERT, "insert+1c")
return "break"

self.insert(tk.INSERT, stack.pop(), self.base.theme.editors.bracket_colors[(i%3)] if i > -1 else 'red')
else:
self.insert(tk.INSERT, e.char, 'red')
Expand All @@ -244,12 +250,10 @@ def complete_pair(self, e: tk.Event, tag=None):

# if there is no selection, insert the character and move cursor inside the pair
if tag:
self.insert(tk.INSERT, char, tag)
self.insert(tk.INSERT, " ")
self.insert(tk.INSERT, end, tag)
self.insert(tk.INSERT, char + end, tag)
else:
self.insert(tk.INSERT, char + end)
self.mark_set(tk.INSERT, "insert-2c")
self.mark_set(tk.INSERT, "insert-1c")
return "break"

def remove_pair(self, _: tk.Event):
Expand Down

0 comments on commit 88e4329

Please sign in to comment.