Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "highlight surrounding quote/bracket" behavior when a selection is active #543

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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