Skip to content

Commit

Permalink
Make line copy/cut/delete while no selection optional
Browse files Browse the repository at this point in the history
By adding disableLineCopyCutDelete.xml in "%APPDATA%\Notepad++\" directory (or in the Notepad++ installed directory in portable mode) to prevent:
1. Hard coded Shift-DEL shortcut delete whole line while no selection.
2. Copy command (Ctrl-C) copy whole line (without selection).
3. Cut command (Ctrl-X) cut whole line (without selection).

Note: the old disableHardCodedShiftDelete.xml (of 53b5055) is canceled, the new disableLineCopyCutDelete.xml is used instead.

Ref: notepad-plus-plus#14296 (comment)
  • Loading branch information
donho committed Dec 22, 2023
1 parent 7419770 commit 1f7687d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
20 changes: 14 additions & 6 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,14 @@ void Notepad_plus::command(int id)
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
if (_pEditView->hasSelection())
_pEditView->execute(WM_CUT);
else
{
bool useLinCopyCut = (NppParameters::getInstance()).useLineCopyCutDelete();
if (useLinCopyCut)
_pEditView->execute(SCI_LINECUT); // Ctrl + X: without selected text, it will cut the whole line.
}
}
break;
}
Expand All @@ -373,10 +377,14 @@ void Notepad_plus::command(int id)
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
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.
}
}
else // Search result
{
Expand Down
25 changes: 13 additions & 12 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,18 +1663,19 @@ bool NppParameters::load()
_column2MultiSelect = false;
}

//-------------------------------------------------------------//
// disableHardCodedShiftDelete.xml //
// This empty xml file is optional - user adds this empty file //
// manually in order to prevent hard coded Shift-DEL shortcut //
// delete whole line while no selection. //
//-------------------------------------------------------------//
std::wstring disableHardCodedShiftDeletePath = _userPath;
pathAppend(disableHardCodedShiftDeletePath, TEXT("disableHardCodedShiftDelete.xml"));

if (PathFileExists(disableHardCodedShiftDeletePath.c_str()))
{
_useHardCodedShiftDelete = false;
//----------------------------------------------------------------------------------//
// disableLineCopyCutDelete.xml //
// This empty xml file is optional - user adds this empty file manually to prevent: //
// 1. Hard coded Shift-DEL shortcut delete whole line while no selection. //
// 2. Copy command (Ctrl-C) copy whole line (without selection). //
// 3. Cut command (Ctrl-X) cut whole line (without selection). //
//----------------------------------------------------------------------------------//
std::wstring disableLineCopyCutDeletePath = _userPath;
pathAppend(disableLineCopyCutDeletePath, TEXT("disableLineCopyCutDelete.xml"));

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

return isAllLaoded;
Expand Down
4 changes: 2 additions & 2 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ class NppParameters final
bool isSelectFgColorEnabled() const { return _isSelectFgColorEnabled; };
bool isRegForOSAppRestartDisabled() const { return _isRegForOSAppRestartDisabled; };
bool doColumn2MultiSelect() const { return _column2MultiSelect; };
bool useHardCodedShiftDelete() const { return _useHardCodedShiftDelete; };
bool useLineCopyCutDelete() const { return _useLineCopyCutDelete; };

private:
bool _isAnyShortcutModified = false;
Expand Down Expand Up @@ -1947,7 +1947,7 @@ class NppParameters final
bool _isSelectFgColorEnabled = false;
bool _isRegForOSAppRestartDisabled = false;
bool _column2MultiSelect = true;
bool _useHardCodedShiftDelete = true;
bool _useLineCopyCutDelete = true;

bool _doNppLogNetworkDriveIssue = false;
bool _doNppLogNulContentCorruptionIssue = false;
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ 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()).useHardCodedShiftDelete();
bool useHardCodedShiftDelete = (NppParameters::getInstance()).useLineCopyCutDelete();

if (wParam == VK_DELETE)
{
Expand Down

0 comments on commit 1f7687d

Please sign in to comment.