-
Notifications
You must be signed in to change notification settings - Fork 7
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
Improve "highlight surrounding quote/bracket" behavior when a selection is active #543
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior is a bit odd (though it is exactly as you described and as expected) if you double click a word within quotes to select it, e.g. “double click on this word please”
, because the first click causes the quotes to be highlighted then the second removes the highlight. Even if you aren't double clicking, if you just select something to edit it, the quote highlight vanishes then reappears, possibly a bit distractingly, as you work within a quoted or bracketed sentence/paragraph.
Sorry to have only just thought of this, but would a better alternative when there's a selection be to highlight the quotes/brackets that surround the selection (not just the insert cursor)?
I think all that would be needed would be to change highlight_single_pair_bracketing_cursor
slightly. At the moment, it gets the insert position into cursor
and uses that as the search_from_index
argument to the search backward and search forward. Instead, if there's a selection, it could use the start of the first sel
range for the search backward loop, and the end of the last sel
range for the search forward loop.
Something like this before the first loop:
if sel_ranges := maintext().selected_ranges():
cursor = sel_ranges[0].start.index()
else:
cursor = maintext().get_insert_index().index()
then this before the second loop:
if sel_ranges:
cursor = sel_ranges[-1].end.index()
What do you think?
That seems reasonable, and actually I had wondered briefly about it myself. I didn't do it as I wasn't sure how, but since you suggest what sounds like a workable solution, I'll give that a try. |
ae37dee
to
1acb804
Compare
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 DistributedProofreaders#541
1acb804
to
c5a99a9
Compare
Rewrote to look around the selection rather than around the cursor, as @windymilla suggested. And therefore it does highlight even when a selection is active. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tangledhelix - I'm not sure if it's an artifact of your rebasing or my fetching of the remote branch, but it appears to me as though it's always using light colors for the cursor line and the align column, even when my theme is dark. Are you seeing the same? If not, I'm happy to go ahead and merge this and untangle anything later once all these related PRs are merged.
After a little more investigation, I suspect the tags are being set up before the theme is being applied to maintext |
In fact, I don't think there is any way for the code as it stands to change the highlight colors when the theme is changed. Not directly related to this PR - it was the refactoring PR #544, I think, which I obviously didn't test thoroughly enough |
Proposal to resolve that:
|
Yes, I'm happy with that behavior in this circumstance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks
Fixes #541