Hi. This is a fix to an issue reported in Notepad++ repo. All tests passed :) See the comments for more info.
--- a/src/Editor.cxx Sun Nov 24 15:19:50 2024 +0100
+++ b/src/Editor.cxx Sun Nov 24 15:44:34 2024 +0100
@@ -999,21 +999,25 @@
// if selection doesn't end at the beginning of a line greater than that of the start,
// then set it at the beginning of the next one
Sci::Position selectionEnd = SelectionEnd().Position();
- const Sci::Line endLine = pdoc->SciLineFromPosition(selectionEnd);
+ Sci::Line endLine = pdoc->SciLineFromPosition(selectionEnd);
const Sci::Position beginningOfEndLine = pdoc->LineStart(endLine);
bool appendEol = false;
if (selectionEnd > beginningOfEndLine
|| selectionStart == selectionEnd) {
selectionEnd = pdoc->LineStart(endLine + 1);
appendEol = (selectionEnd == pdoc->Length() && pdoc->SciLineFromPosition(selectionEnd) == endLine);
+ endLine = pdoc->SciLineFromPosition(selectionEnd);
}
// if there's nowhere for the selection to move
// (i.e. at the beginning going up or at the end going down),
// stop it right there!
+ bool docEndLineEmpty = pdoc->LineStart(endLine) == pdoc->Length();
if ((selectionStart == 0 && lineDelta < 0)
- || (selectionEnd == pdoc->Length() && lineDelta > 0)
- || selectionStart == selectionEnd) {
+ || (selectionEnd == pdoc->Length() && lineDelta > 0
+ && !docEndLineEmpty) // allow moving when end line of document is empty
+ || ((selectionStart == selectionEnd)
+ && !(lineDelta < 0 && docEndLineEmpty && selectionEnd == pdoc->Length()))) { // allow moving-up last empty line
return;
}
Btw, I've noticed the date in
ScintillaHistory.htmlfor Release 5.5.4 is the same as for 5.5.3 :)Committed as [352da4] with an added
const. The expression to exit is ugly but I didn't find a good way to simplify it.Dates in the histories are updated when the release is scheduled.
Related
Commit: [352da4]
Thanks!
Handling the edge cases most of the time uglify the code IMO 🤷♀️
Maybe changing assumptions or even the definition of some core functions would simplify this whole function but it's risky 😈
following change can save extra
SciLineFromPosition()call:Last edit: Zufu Liu 2024-12-04
This doesn't appear to be a measurable performance improvement since the extra call only occurs at the document end and the whole move lines command is large compared to a single
LineFromPosition. Is the code shorter or neater? Not really.