Skip to content

Commit

Permalink
Fix hasSelection wrongly detected
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Nov 7, 2023
1 parent 2fb8d7f commit 1fafd0d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1fafd0d

Please sign in to comment.