-
-
Notifications
You must be signed in to change notification settings - Fork 715
Fix OffsetTextInfo.collapse() and OffsetTextInfo.move() #18348
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
base: master
Are you sure you want to change the base?
Conversation
See test results for failed build of commit e48645facd |
@nvdaes, could you test that this doesn't break #17430? |
Thanks @mltony . This works for me as expected in Notepad++ with braille when moving to the next line, if last line is empty. |
Thanks @nvdaes! |
This is an interesting find. I'm afraid though that this implementation might report nonexisting blank lines when moving by line with the review cursor. I guess this clarifies why the chrome test behavior differs now. Also note that the comment is no longer accurate now. It says: I agree though that what you said in an earlier comment in the previous pr is true, namely that the last empty line of a document has a length of 0. Treating that as 1 won't work due to the highLimit in the Note also that The story length of an empty notepad classic document (i.e. a default EditTextInfo) is 1, not 0. It uses a + 1 trick, though there is an ambiguous comment saying that an off by one error is created by the + 1. I think this means no more than that this trick causes the story length to be reported one higher than the actual length. It seems that EditTextInfo doesn't treat line breaks as actual characters. A quick fix would be doing _getStoryLength + 1, but this introduces the same ambiguity as in EditTextInfo. |
I don't think so. If I read this code correctly, However having said that, I agree that any change in this low-level TextInfo implementation might cause undesired behavior somewhere else, so I'll keep an eye on any bug reports if there are any. Also updated the comment. |
I can't find any strange behavior with the review cursor in neither classic notepad nor NP++. NP++ improves in such a way that the review cursor can now also reach the last line, which is great. |
Co-authored-by: Leonard de Ruijter <[email protected]>
I just added the merge early label since I think this needs some broader testing in Alpha. |
@@ -664,7 +668,7 @@ def move(self, unit, direction, endPoint=None): | |||
count = 0 | |||
lowLimit = 0 | |||
highLimit = self._getStoryLength() | |||
if self.allowMoveToOffsetPastEnd and unit == textInfos.UNIT_CHARACTER: |
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.
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 don't remember the specifics. However, I'll point out that "the very last position" (and what is supported there) can differ between text implementations.
- For some non-editable implementations, the length might not be a valid start offset.
- Normally, length is considered part of the final line, not a blank line. That raises the question: does it actually make sense to move there by line or paragraph? Could that confuse some callers to behave like there is a blank line at the end when there in fact isn't?
I don't have answers to these points, but they need to be considered if they haven't already. Note also that I haven't read this entire thread, only skimmed it, so I might have missed something.
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.
Would we consider this an API breaking change?
Co-authored-by: Sean Budd <[email protected]>
@seanbudd, regarding API breaking, I just wanted to mention yet again that this is also a bug. As I mentioned before, without this PR the entire textInfo API is unusable as there is no reliable way to collapse textInfo and this breaks a few of my add-ons. It would be unfortunate if we have to wait until next major release to fix a bug like that. |
Link to issue number:
Fixes #18320.
This is my second attempt to fix it without breaking #17430. For the reference, the first attempt was #18338, which is abandoned, and which didn't fix the root cause, but just decoupled @nvdaes's commit from TextInfo API. This PR however fixes the root cause of #17430.
Summary of the issue:
Commit 70cd311 by @nvdaes introduced a bug in TextInfo API:
TextInfo.collapse()
now unnecessarily jumps to the next paragraph in Notepad++. This bug also made its way into 2025.1 release.I investigated the braille issue #17430 further and it boiled down to an issue with
OffsetTextInfo.move()
implementation: it turns out that unless it moves by character, it is unable to move to the very last position in the document. FixingOffsetTextInfo.move()
implementation.Description of user facing changes:
N/A
Description of developer facing changes:
OffsetTextInfo.collapse()
now works correctly in Notepad++.OffsetTextInfo.move()
can now move to the very last position even when unit is set to line or paragraph.Description of development approach:
In
OffsetTextInfo.move()
modified the condition whenself.allowMoveToOffsetPastEnd
to increasehighLimit
regardless of current unit - previously this would only allow when unit is character.Removed
ScintillaTextInfo.expand()
override.Testing strategy:
Tested with use case provided in TextInfo.collapse(end=True) moves textInfo to the next paragraph in Notepad++ #18320.
Tested that
OffsetTextInfo.move('line', 1)
can now successfully go to the very last line in Notepad++ even if the last line is empty. This should be the proper fix for Notepad++: braille doesn't move to the next line if last line is empty #17430.Known issues with pull request:
N/A
Code Review Checklist:
@coderabbitai summary