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);