diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index af4b6c3d8222..2f2efa3de8e8 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2555,7 +2555,7 @@ void Notepad_plus::enableCommand(int cmdID, bool doEnable, int which) const void Notepad_plus::checkClipboard() { - bool hasSelection = (_pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND)); + bool hasSelection = _pEditView->hasSelection(); bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0); enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR); enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index a4fa3be00b3b..28b7d80158d0 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -2012,6 +2012,9 @@ void Notepad_plus::command(int id) (id == IDM_EDIT_MULTISELECTALLMATCHCASE ? SCFIND_MATCHCASE : (id == IDM_EDIT_MULTISELECTALLWHOLEWORD ? SCFIND_WHOLEWORD: SCFIND_MATCHCASE| SCFIND_WHOLEWORD)); + // Don't use _pEditView->hasSelection() because when multi-selection is active and main selection has no selection, + // it will cause an infinite loop on SCI_MULTIPLESELECTADDEACH. See: + // https://github.com/notepad-plus-plus/notepad-plus-plus/pull/14330#issuecomment-1797080251 bool hasSelection = (_pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND)); if (!hasSelection) _pEditView->expandWordSelection(); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 2a272fb24827..08b99aa606f2 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -544,8 +544,7 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa SHORT shift = GetKeyState(VK_SHIFT); if ((shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000)) { - bool hasSelection = (execute(SCI_GETSELECTIONSTART) != execute(SCI_GETSELECTIONEND)); - if (!hasSelection) + if (!hasSelection()) { execute(SCI_LINEDELETE); return TRUE; @@ -562,8 +561,7 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa SHORT shift = GetKeyState(VK_SHIFT); if ((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000)) { - bool hasSelection = (execute(SCI_GETSELECTIONSTART) != execute(SCI_GETSELECTIONEND)); - if (!hasSelection) + if (!hasSelection()) { execute(wParam == 'C' ? SCI_LINECOPY : SCI_LINECUT); //return TRUE; diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index e38cb8846708..9e9671ceb0ba 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -717,6 +717,8 @@ friend class Finder; void notifyMarkers(Buffer * buf, bool isHide, size_t location, bool del); void runMarkers(bool doHide, size_t searchStart, bool endOfDoc, bool doDelete); + bool hasSelection() const { return !execute(SCI_GETSELECTIONEMPTY); }; + bool isSelecting() const { static Sci_CharacterRangeFull previousSelRange = getSelection(); Sci_CharacterRangeFull currentSelRange = getSelection();