-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Make selection an exclusive range #18106
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
_fillColorBitmap(row, x1, end, fgColor, bgColor); | ||
|
||
// Return early if we couldn't paint the whole region (either this was not the last row, or | ||
// it was the last row but the highlight ends outside of our x range.) | ||
// We will resume from here in the next call. | ||
if (!isFinalRow || hiEnd.x /*inclusive*/ >= x2 /*exclusive*/) | ||
if (!isFinalRow || hiEnd.x > x2) |
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.
BTW I think we may have made a mistake here due to my poor understanding of this code. Probably needs to be mulled over once more...
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.
yes, be careful - this is used in TWO places. search highlights and selection rendering. they're both inclusive today. this PR only says it changes one of them.
{ | ||
const auto l = static_cast<ptrdiff_t>(_sr.left); | ||
const auto t = static_cast<ptrdiff_t>(_sr.top); | ||
const auto w = static_cast<ptrdiff_t>(std::max(0, _sr.right - _sr.left + 2)); |
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.
I think this should be +1. BTW is this function really needed? We already have WalkInBounds
with the allowEndExclusive
parameter that we could set to false
no?
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.
Ah, so allowEndExclusive
is slightly different. EndExclusive = (Left, BottomExclusive)
. allowEndExclusive
was designed to make WalkInBounds(true)
still walk from Left
--> RightInclusive
, but when we get to the last cell of the bottom inclusive row, we wrap onto the next line (EndExclusive). This made it so that we're able to represent the UIA start/end as an exclusive range, and we'd be able to include the last cell of the buffer by making end = EndExclusive.
In hindsight, I think the right move should've been to make EndExclusive = (RightExclusive, BottomInclusive)
. This PR makes selection do that and adds these extra APIs. I think it's much cleaner. But yeah, I wouldn't want to port UIA over to this system until it gets reviewed and merged. So I'm making that work a part of #4423 as a follow-up (where we should be able to remove EndExclusive
altogether).
As for the +1
, I honestly don't remember why I made it +2
... you're probably right. I'll make that change and validate.
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.
IOU a review here - thanks for doing it!
However, all of the tests exploded so... I may wait. :P |
This comment has been minimized.
This comment has been minimized.
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.
Have you tested...
- detecting URls
- selecting URLs
- search highlights (with and without regexes)
@@ -342,9 +342,8 @@ try | |||
const til::rect vp{ _viewport.ToExclusive() }; | |||
for (auto&& sp : spans) | |||
{ | |||
sp.iterate_rows(bufferWidth, [&](til::CoordType row, til::CoordType min, til::CoordType max) { | |||
sp.iterate_rows_exclusive(bufferWidth, [&](til::CoordType row, til::CoordType min, til::CoordType max) { |
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.
careful! this touches conhost code too. ... !
this may make selections not work properly in conhost
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.
Testing out Host.exe, this PR does change selection to be exclusive there too. Pivoting the selection is a bit weird now as shift+clicking before the pivot highlights the selected cell, whereas doing so after the pivot highlights up to the cell the pointer is on.
I'm able to polish Conhost to work more nicely too, but is that something we want? Or should I explore how to keep Conhost the same?
Urls are detected in all instances below. Clicking the url:
Method: Enter mark mode --> Shift+Tab to select the url
Regex: Non-regex: Looks like I've got a bit of work to do. |
Summary of the Pull Request
Selection is generally stored as an inclusive start and end. This PR makes the end exclusive which now allows degenerate selections, namely in mark mode. This also modifies mouse selection to round to the nearest cell boundary (see #5099) and improves word boundaries to be a bit more modern and make sense for degenerate selections (similar to #15787).
References and Relevant Issues
Closes #5099
Closes #13447
Closes #17892
Detailed Description of the Pull Request / Additional comments
GetWordStart
-->GetWordStart2
). That migration is going to be a part of Refactor Word Expansion in TextBuffer #4423 to reduce the risk of breaking UIA.BottomInclusiveRightExclusive()
will replaceEndExclusive
in the UIA codeiterate_rows_exclusive
is similar toiterate_rows
, except it has handling for RightExclusiveiterate_rows_exclusive
for proper handling (this actually fixed a lot of our issues)_drawHighlighted
(this is a boundary where we got inclusive coords and made them exclusive, but now we don't need that!)_ConvertToBufferCell()
: add a param to allow for RightExclusive or clamp it to RightInclusive (original behavior). Both are useful!GetWordStart2
andGetWordEnd2
to improve word boundaries and make them feel right now that the selection an exclusive range.IsInBounds
-->IsInExclusiveBounds
for safety and correctnessTriggerSelection
toSelectNewRegion
TriggerSelection
in a different layer, but it turns out, UIA'sSelect
function wouldn't actually update the renderer. Whoops! This fixes that._getTerminalPosition
now has a new param to round to the nearest cell (see Mouse selection should begin and end at nearest cell boundary #5099)TermControlUIAProvider::GetSelectionRange
no need to convert from inclusive range to exclusive range anymore!TextBuffer::GetPlainText
now works on an exclusive range, so no need to convert the range anymore!Validation Steps Performed
This fundamental change impacts a lot of scenarios:
We should definitely bug bash this to get good coverage.
Follow-ups
EndExclusive
as well when we do that. This'll also be an opportunity to modernize that code and use moretil
classes.