Skip to content

Commit

Permalink
Fix visual glichy on multi-paste
Browse files Browse the repository at this point in the history
This PR removes Shift-DEL Ctrl-INS & Shift-INS shortcut from Scintilla.
Ref: notepad-plus-plus#14401 (comment)

Now for Copy/Cut/Paste commands and their shortcut are coherent. ie. if user remaps the shortcuts of these 3 commands, both single/multiple selection operation with the commands in question will follow the changed shortcuts.

It also fixes 2 bugs:
1. visual glitch problem of read-only while multi-pasting.
2. the shortcut **Ctrl-C** in Search results works now.

Fix notepad-plus-plus#14410, close notepad-plus-plus#14423
  • Loading branch information
donho committed Nov 29, 2023
1 parent 7deb12a commit 0978b2e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 81 deletions.
58 changes: 39 additions & 19 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,37 @@ void Notepad_plus::command(int id)
}

case IDM_EDIT_CUT:
if (!_pEditView->hasSelection()) // Ctrl + X: without selected text, it will cut the whole line.
_pEditView->execute(SCI_LINECUT);
else
_pEditView->execute(WM_CUT);

{
HWND focusedHwnd = ::GetFocus();
if (focusedHwnd == _pEditView->getHSelf())
{
if (!_pEditView->hasSelection()) // Ctrl + X: without selected text, it will cut the whole line.
_pEditView->execute(SCI_LINECUT);
else
_pEditView->execute(WM_CUT);
}
break;
}

case IDM_EDIT_COPY:
if (!_pEditView->hasSelection()) // Ctrl + C: without selected text, it will copy the whole line.
_pEditView->execute(SCI_LINECOPY);
else
_pEditView->execute(WM_COPY);
{
HWND focusedHwnd = ::GetFocus();
if (focusedHwnd == _pEditView->getHSelf())
{
if (!_pEditView->hasSelection()) // Ctrl + C: without selected text, it will copy the whole line.
_pEditView->execute(SCI_LINECOPY);
else
_pEditView->execute(WM_COPY);
}
else // Search result
{
Finder* finder = _findReplaceDlg.getFinderFrom(focusedHwnd);
if (finder)
finder->scintillaExecute(WM_COPY);
}

break;
}

case IDM_EDIT_COPY_LINK:
{
Expand Down Expand Up @@ -448,18 +465,21 @@ void Notepad_plus::command(int id)
case IDM_EDIT_PASTE:
{
std::lock_guard<std::mutex> lock(command_mutex);

size_t nbSelections = _pEditView->execute(SCI_GETSELECTIONS);
Buffer* buf = getCurrentBuffer();
bool isRO = buf->isReadOnly();
if (nbSelections > 1 && !isRO)
HWND focusedHwnd = ::GetFocus();
if (focusedHwnd == _pEditView->getHSelf())
{
bool isPasteDone = _pEditView->pasteToMultiSelection();
if (isPasteDone)
return;
}
size_t nbSelections = _pEditView->execute(SCI_GETSELECTIONS);
Buffer* buf = getCurrentBuffer();
bool isRO = buf->isReadOnly();
if (nbSelections > 1 && !isRO)
{
bool isPasteDone = _pEditView->pasteToMultiSelection();
if (isPasteDone)
return;
}

_pEditView->execute(SCI_PASTE);
_pEditView->execute(SCI_PASTE);
}
}
break;

Expand Down
18 changes: 9 additions & 9 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ static const WinMenuKeyDefinition winKeyDefs[] =

// { VK_NULL, IDM_EDIT_UNDO, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_REDO, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_CUT, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_COPY, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_PASTE, false, false, false, nullptr },
{ VK_X, IDM_EDIT_CUT, true, false, false, nullptr },
{ VK_C, IDM_EDIT_COPY, true, false, false, nullptr },
{ VK_V, IDM_EDIT_PASTE, true, false, false, nullptr },
// { VK_NULL, IDM_EDIT_DELETE, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_SELECTALL, false, false, false, nullptr },
{ VK_B, IDM_EDIT_BEGINENDSELECT, true, false, true, nullptr },
Expand Down Expand Up @@ -471,12 +471,12 @@ static const ScintillaKeyDefinition scintKeyDefs[] =
//Scintilla command name, SCINTILLA_CMD_ID, Ctrl, Alt, Shift, V_KEY, NOTEPAD++_CMD_ID
// -------------------------------------------------------------------------------------------------------------------
//
{TEXT("SCI_CUT"), SCI_CUT, true, false, false, VK_X, IDM_EDIT_CUT},
{TEXT(""), SCI_CUT, false, false, true, VK_DELETE, 0},
{TEXT("SCI_COPY"), SCI_COPY, true, false, false, VK_C, IDM_EDIT_COPY},
{TEXT(""), SCI_COPY, true, false, false, VK_INSERT, 0},
{TEXT("SCI_PASTE"), SCI_PASTE, true, false, false, VK_V, IDM_EDIT_PASTE},
{TEXT(""), SCI_PASTE, false, false, true, VK_INSERT, 0},
// {TEXT("SCI_CUT"), SCI_CUT, true, false, false, VK_X, IDM_EDIT_CUT},
// {TEXT(""), SCI_CUT, false, false, true, VK_DELETE, 0},
// {TEXT("SCI_COPY"), SCI_COPY, true, false, false, VK_C, IDM_EDIT_COPY},
// {TEXT(""), SCI_COPY, true, false, false, VK_INSERT, 0},
// {TEXT("SCI_PASTE"), SCI_PASTE, true, false, false, VK_V, IDM_EDIT_PASTE},
// {TEXT(""), SCI_PASTE, false, false, true, VK_INSERT, 0},
{TEXT("SCI_SELECTALL"), SCI_SELECTALL, true, false, false, VK_A, IDM_EDIT_SELECTALL},
{TEXT("SCI_CLEAR"), SCI_CLEAR, false, false, false, VK_DELETE, IDM_EDIT_DELETE},
{TEXT("SCI_CLEARALL"), SCI_CLEARALL, false, false, false, 0, 0},
Expand Down
20 changes: 20 additions & 0 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3412,6 +3412,26 @@ bool FindReplaceDlg::removeFinder(Finder *finder2remove)
return false;
}

Finder* FindReplaceDlg::getFinderFrom(HWND hwnd)
{
if (_pFinder && _pFinder->isCreated())
{
if (_pFinder->_scintView.getHSelf() == hwnd)
return _pFinder;

if (!_findersOfFinder.empty())
{
for (const auto& finder : _findersOfFinder)
{
if (finder->_scintView.getHSelf() == hwnd)
return finder;
}
}
}

return nullptr;
}

void FindReplaceDlg::setSearchText(TCHAR * txt2find)
{
HWND hCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
Expand Down
8 changes: 7 additions & 1 deletion PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ friend class FindReplaceDlg;
void setVolatiled(bool val) { _canBeVolatiled = val; };
generic_string getHitsString(int count) const;

LRESULT scintillaExecute(UINT msg, WPARAM wParam = 0, LPARAM lParam = 0) const {
return _scintView.execute(msg, wParam, lParam);
}
protected :
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
bool notify(SCNotification *notification);
Expand Down Expand Up @@ -282,7 +285,9 @@ public :
void findAllIn(InWhat op);
void setSearchText(TCHAR * txt2find);

void gotoNextFoundResult(int direction = 0) {if (_pFinder) _pFinder->gotoNextFoundResult(direction);};
void gotoNextFoundResult(int direction = 0) const {
if (_pFinder) _pFinder->gotoNextFoundResult(direction);
};

void putFindResult(int result) {
_findAllResult = result;
Expand Down Expand Up @@ -392,6 +397,7 @@ public :
Finder * createFinder();
bool removeFinder(Finder *finder2remove);
DIALOG_TYPE getCurrentStatus() {return _currentStatus;};
Finder* getFinderFrom(HWND hwnd);

protected :
void resizeDialogElements(LONG newWidth);
Expand Down
52 changes: 0 additions & 52 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
::SendMessage(_hParent, WM_NOTIFY, LINKTRIGGERED, reinterpret_cast<LPARAM>(&notification));

}
else if (wParam == 'V')
{
if (_isMultiPasteActive)
{
Buffer* buf = getCurrentBuffer();
buf->setUserReadOnly(false);
_isMultiPasteActive = false;
::SendMessage(_hParent, NPPM_INTERNAL_CHECKUNDOREDOSTATE, 0, 0);
}
}
break;
}

Expand Down Expand Up @@ -648,48 +638,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
}

}
else
{
switch (wParam)
{
//
// 2 shortcuts:
// Ctrl + C: without selected text, it will copy the whole line.
// Ctrl + X: without selected text, it will cut the whole line.
//
case 'C':
case 'X':
{
if (((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000)) && !hasSelection())
{
execute(wParam == 'C' ? SCI_LINECOPY : SCI_LINECUT);
//return TRUE;
// No return and let Scintilla procedure to continue
}
}
break;

case 'V':
{
if ((ctrl & 0x8000) && !(alt & 0x8000) && !(shift & 0x8000))
{
Buffer* buf = getCurrentBuffer();
bool isRO = buf->isReadOnly();
size_t nbSelections = execute(SCI_GETSELECTIONS);
if (nbSelections > 1 && !isRO)
{
if (pasteToMultiSelection())
{
// Hack for preventing the char "SYN" (0x16) from being adding into edit zone
buf->setUserReadOnly(true);

_isMultiPasteActive = true; // It will be set false with WM_KEYUP message
}
}
}
}
}
}
break;
}

Expand Down

0 comments on commit 0978b2e

Please sign in to comment.