From 4bf662d031ff4cb55f9d919f4fac85f1e1af7ae1 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Wed, 1 Jul 2020 19:50:20 -0400 Subject: [PATCH] Fix condition where Split Lines does one too many lines Fix #8504, close #8507 --- PowerEditor/src/NppCommands.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 7bdfe45d..0ec8646a 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1415,18 +1415,27 @@ void Notepad_plus::command(int id) break; case IDM_EDIT_SPLIT_LINES: - _pEditView->execute(SCI_TARGETFROMSELECTION); - if (_pEditView->execute(SCI_GETEDGEMODE) == EDGE_NONE) + { + pair lineRange = _pEditView->getSelectionLinesRange(); + if (lineRange.first != -1) { - _pEditView->execute(SCI_LINESSPLIT); + auto anchorPos = _pEditView->execute(SCI_POSITIONFROMLINE, lineRange.first); + auto caretPos = _pEditView->execute(SCI_GETLINEENDPOSITION, lineRange.second); + _pEditView->execute(SCI_SETSELECTION, caretPos, anchorPos); + _pEditView->execute(SCI_TARGETFROMSELECTION); + if (_pEditView->execute(SCI_GETEDGEMODE) == EDGE_NONE) + { + _pEditView->execute(SCI_LINESSPLIT); + } + else + { + auto textWidth = _pEditView->execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast("P")); + auto edgeCol = _pEditView->execute(SCI_GETEDGECOLUMN); + _pEditView->execute(SCI_LINESSPLIT, textWidth * edgeCol); + } } - else - { - auto textWidth = _pEditView->execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast("P")); - auto edgeCol = _pEditView->execute(SCI_GETEDGECOLUMN); - _pEditView->execute(SCI_LINESSPLIT, textWidth * edgeCol); - } - break; + } + break; case IDM_EDIT_JOIN_LINES: _pEditView->execute(SCI_TARGETFROMSELECTION);