Fix hasSelection wrongly detected

Fix #14322, close #14330
pull/14339/head
Don Ho 1 year ago
parent 2fb8d7fc77
commit 1fafd0dc0b

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

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

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

@ -717,6 +717,8 @@ public:
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();

Loading…
Cancel
Save