Skip to content

Commit

Permalink
Highlight surround quotes/brackets around select
Browse files Browse the repository at this point in the history
Instead of only highlighting quotes/brackets around a cursor/insertion
point, also check if a selection is active, and if so, highlight as if
the selection were a cursor.

Fixes #541
  • Loading branch information
tangledhelix committed Nov 28, 2024
1 parent e8b2891 commit c5a99a9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/guiguts/maintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,10 @@ def highlight_single_pair_bracketing_cursor(
them with the given tagname. If charpair is not specified, a default regex
of f"[{startchar}{endchar}]" will be used.
If a selection is active, the entire selected region is considered to be
the cursor, and pairs surrounding that region are marked; characters
inside the selected region will not be considered.
Args:
startchar: opening char of pair (e.g. '(')
endchar: closing chair of pair (e.g. ')')
Expand All @@ -2669,6 +2673,11 @@ def highlight_single_pair_bracketing_cursor(
self.focus_widget(), 80
)

if sel_ranges := maintext().selected_ranges():
cursor = sel_ranges[0].start.index()
else:
cursor = maintext().get_insert_index().index()

# search backward for the startchar
startindex = self.search_for_base_character_in_pair(
top_index,
Expand All @@ -2682,6 +2691,9 @@ def highlight_single_pair_bracketing_cursor(
if not startindex:
return

if sel_ranges:
cursor = sel_ranges[-1].end.index()

# search forward for the endchar
endindex = self.search_for_base_character_in_pair(
top_index, cursor, bot_index, startchar, endchar, charpair=charpair
Expand Down

0 comments on commit c5a99a9

Please sign in to comment.