Skip to content

Commit

Permalink
Restore Shift-DEL, Ctrl-INS and Shift-INS & fix Ctrl+V can't paste in…
Browse files Browse the repository at this point in the history
…to the text fields of forms for certain plugins

This PR restores shortcuts Shift-DEL, Ctrl-INS and Shift-INS for Cut / Copy / Paste respectively.
the action to delete entire line without selection is removed in this PR due to its shortcut Shift-DEL has triggered several critical issues.

To delete entire line, the users are encouraged to use Scintilla default shortcuts set in Shortcut Mapper: Ctrl-Shift-L (SCI_LINEDELETE). User can remap it to another shortcut via Shortcut mapper.

Fix #14568, fix #14470, fix #14571, close #14557, close #14569
  • Loading branch information
donho committed Jan 11, 2024
1 parent f7de207 commit f7c44b4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 59 deletions.
3 changes: 3 additions & 0 deletions PowerEditor/src/Notepad_plus.cpp
Expand Up @@ -2567,8 +2567,11 @@ void Notepad_plus::checkClipboard()
{
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);

enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR);
enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR);
enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU);
enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU);
enableCommand(IDM_EDIT_PROPERCASE_FORCE, hasSelection, MENU);
Expand Down
35 changes: 20 additions & 15 deletions PowerEditor/src/NppCommands.cpp
Expand Up @@ -360,15 +360,20 @@ void Notepad_plus::command(int id)
HWND focusedHwnd = ::GetFocus();
if (focusedHwnd == _pEditView->getHSelf())
{
if (_pEditView->hasSelection())
if (_pEditView->hasSelection()) // Cut normally
{
_pEditView->execute(WM_CUT);
else
}
else // Cul the entire line

This comment has been minimized.

Copy link
@fml2

fml2 Jan 11, 2024

"cul" -> "cut"?

This comment has been minimized.

Copy link
@donho

donho Jan 13, 2024

Author Member

"Cul" in French means "Ass" - I guess unconsciously I have had enough for this issue - ("ras le cul" == "tired of this issue") :)

{
bool useLinCopyCut = (NppParameters::getInstance()).useLineCopyCutDelete();
if (useLinCopyCut)
_pEditView->execute(SCI_LINECUT); // Ctrl + X: without selected text, it will cut the whole line.
_pEditView->execute(SCI_COPYALLOWLINE);
_pEditView->execute(SCI_LINEDELETE);
}
}
else
{
::SendMessage(focusedHwnd, WM_CUT, 0, 0);
}
break;
}

Expand All @@ -377,20 +382,16 @@ void Notepad_plus::command(int id)
HWND focusedHwnd = ::GetFocus();
if (focusedHwnd == _pEditView->getHSelf())
{
if (_pEditView->hasSelection())
_pEditView->execute(WM_COPY);
else
{
bool useLinCopyCut = (NppParameters::getInstance()).useLineCopyCutDelete();
if (useLinCopyCut)
_pEditView->execute(SCI_LINECOPY); // Ctrl + C: without selected text, it will copy the whole line.
}
_pEditView->execute(SCI_COPYALLOWLINE); // Copy selected text if any.
// Otherwise copy the entire line with EOL, for pasting before any line where the caret is.

This comment has been minimized.

Copy link
@alankilborn

alankilborn Jan 11, 2024

Contributor

Is ", for pasting before any line where the caret is." relevant?

This comment has been minimized.

Copy link
@donho

donho Jan 31, 2024

Author Member

Not to me.
But such feature is demanded by a lot of ppl.

This comment has been minimized.

Copy link
@alankilborn

alankilborn Jan 31, 2024

Contributor

I meant, why not just say the first part (before the comma) and leave it at that? To me, the part after the comma is confusing, because it implies there is more to it, and there really isn't. The first part says it all.

}
else // Search result
else
{
Finder* finder = _findReplaceDlg.getFinderFrom(focusedHwnd);
if (finder)
if (finder) // Search result
finder->scintillaExecute(WM_COPY);
else
::SendMessage(focusedHwnd, WM_COPY, 0, 0);
}

break;
Expand Down Expand Up @@ -488,6 +489,10 @@ void Notepad_plus::command(int id)

_pEditView->execute(SCI_PASTE);
}
else
{
::SendMessage(focusedHwnd, WM_PASTE, 0, 0);
}
}
break;

Expand Down
47 changes: 13 additions & 34 deletions PowerEditor/src/Parameters.cpp
Expand Up @@ -84,9 +84,16 @@ static const WinMenuKeyDefinition winKeyDefs[] =

// { VK_NULL, IDM_EDIT_UNDO, false, false, false, nullptr },
// { VK_NULL, IDM_EDIT_REDO, false, false, false, nullptr },

{ VK_DELETE, IDM_EDIT_CUT, false, false, true, nullptr },
{ VK_X, IDM_EDIT_CUT, true, false, false, nullptr },

{ VK_INSERT, IDM_EDIT_COPY, true, false, false, nullptr },
{ VK_C, IDM_EDIT_COPY, true, false, false, nullptr },

{ VK_INSERT, IDM_EDIT_PASTE, false, false, true, 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 @@ -472,11 +479,12 @@ static const ScintillaKeyDefinition scintKeyDefs[] =
//Scintilla command name, SCINTILLA_CMD_ID, Ctrl, Alt, Shift, V_KEY, NOTEPAD++_CMD_ID
// -------------------------------------------------------------------------------------------------------------------
//
// {TEXT("SCI_CUT"), SCI_CUT, false, false, true, VK_DELETE, 0},
// {TEXT("SCI_COPY"), SCI_COPY, true, false, false, VK_INSERT, 0},
// {TEXT("SCI_PASTE"), SCI_PASTE, false, false, true, VK_INSERT, 0},
// the above 3 shortcuts will be added dynamically if "disableLineCopyCutDelete.xml" is present.

//{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"), SCI_PASTE, false, false, true, VK_INSERT, IDM_EDIT_PASTE},
{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 Expand Up @@ -1476,35 +1484,6 @@ bool NppParameters::load()
isAllLaoded = false;
}


//-----------------------------------------------------------------------------------//
// disableLineCopyCutDelete.xml //
// This empty xml file is optional - user adds this empty file manually to : //
// 1. prevent hard coded Shift-DEL shortcut deletes whole line while no selection. //
// 2. prevent Copy command (Ctrl-C) copies whole line (without selection). //
// 3. prevent Cut command (Ctrl-X) cuts whole line (without selection). //
// 4. add SCI_CUT (Shift-DEL), SCI_COPY (Ctrl-INS) & SCI_PASTE (Shift-INS) shortcuts //
//-----------------------------------------------------------------------------------//
std::wstring disableLineCopyCutDeletePath = _userPath;
pathAppend(disableLineCopyCutDeletePath, TEXT("disableLineCopyCutDelete.xml"));

if (PathFileExists(disableLineCopyCutDeletePath.c_str()))
{
_useLineCopyCutDelete = false;

//
// Add back SCI_CUT (Shift-DEL), SCI_COPY (Ctrl-INS) & SCI_PASTE (Shift-INS) shortcuts
//
ScintillaKeyMap sci_cut = ScintillaKeyMap(Shortcut("SCI_CUT", false, false, true, static_cast<unsigned char>(VK_DELETE)), SCI_CUT, 0);
_scintillaKeyCommands.push_back(sci_cut);

ScintillaKeyMap sci_copy = ScintillaKeyMap(Shortcut("SCI_COPY", true, false, false, static_cast<unsigned char>(VK_INSERT)), SCI_COPY, 0);
_scintillaKeyCommands.push_back(sci_copy);

ScintillaKeyMap sci_paste = ScintillaKeyMap(Shortcut("SCI_PASTE", false, false, true, static_cast<unsigned char>(VK_INSERT)), SCI_PASTE, 0);
_scintillaKeyCommands.push_back(sci_paste);
}

//------------------------------//
// shortcuts.xml : for per user //
//------------------------------//
Expand Down
11 changes: 1 addition & 10 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Expand Up @@ -525,19 +525,10 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
SHORT shift = GetKeyState(VK_SHIFT);
bool isColumnSelection = (execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN);
bool column2MultSelect = (NppParameters::getInstance()).doColumn2MultiSelect();
bool useHardCodedShiftDelete = (NppParameters::getInstance()).useLineCopyCutDelete();

if (wParam == VK_DELETE)
{
// 1 shortcut:
// Shift + Delete: without selected text, it will delete the whole line.
//
if ((shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000) && !hasSelection() && useHardCodedShiftDelete) // Shift-DEL & no selection
{
execute(SCI_LINEDELETE);
return TRUE;
}
else if (!(shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000)) // DEL & Multi-edit
if (!(shift & 0x8000) && !(ctrl & 0x8000) && !(alt & 0x8000)) // DEL & Multi-edit
{
size_t nbSelections = execute(SCI_GETSELECTIONS);
if (nbSelections > 1) // Multi-edit
Expand Down

0 comments on commit f7c44b4

Please sign in to comment.