From 19a8d747a56e7cb9e543cb807cf08fd95f3d617a Mon Sep 17 00:00:00 2001 From: pawelzwronek Date: Sun, 24 Nov 2024 15:44:34 +0100 Subject: Bug [#2457]. Fix moving line down to empty final line and moving empty final line up. Handle edge cases when moving selected lines. Allow moving the selection when the end line of the document is empty or when moving up the last empty line. --- doc/ScintillaHistory.html | 4 ++++ src/Editor.cxx | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 84cbab7ad..471fc9a3a 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -611,6 +611,10 @@ Bug #2456.
  • + Fix moving line down to empty final line and moving empty final line up. + Bug #2457. +
  • +
  • On GTK, allow middle click to insert multiple times within a document. Geany Issue #2629.
  • diff --git a/src/Editor.cxx b/src/Editor.cxx index bd5a0b2c1..b60d96643 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1003,21 +1003,25 @@ void Editor::MoveSelectedLines(int lineDelta) { // 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! + const 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; } -- cgit v1.2.3