From f1b059414b95fa49c164adaa3cca4e11691bf789 Mon Sep 17 00:00:00 2001
From: Scott Sumner <30118311+sasumner@users.noreply.github.com>
Date: Tue, 14 Jul 2020 20:12:20 -0400
Subject: [PATCH] Add an option to prevent right-click from canceling selection
Fix #8563, close #8564
---
PowerEditor/installer/nativeLang/english.xml | 1 +
PowerEditor/src/Parameters.cpp | 13 +++++++++++-
PowerEditor/src/Parameters.h | 1 +
.../ScitillaComponent/ScintillaEditView.cpp | 20 +++++++++++++++++++
.../src/WinControls/Preference/preference.rc | 13 ++++++------
.../WinControls/Preference/preferenceDlg.cpp | 5 +++++
.../WinControls/Preference/preference_rc.h | 1 +
7 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml
index eb1853674..957e1bba8 100644
--- a/PowerEditor/installer/nativeLang/english.xml
+++ b/PowerEditor/installer/nativeLang/english.xml
@@ -756,6 +756,7 @@ You can define several column markers by using white space to separate the diffe
+
diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp
index f0ffb788a..dc48201c6 100644
--- a/PowerEditor/src/Parameters.cpp
+++ b/PowerEditor/src/Parameters.cpp
@@ -5263,6 +5263,16 @@ void NppParameters::feedScintillaParam(TiXmlNode *node)
_svp._scrollBeyondLastLine = false;
}
+ // Do not change selection or caret position when right-clicking with mouse
+ nm = element->Attribute(TEXT("rightClickKeepsSelection"));
+ if (nm)
+ {
+ if (!lstrcmp(nm, TEXT("yes")))
+ _svp._rightClickKeepsSelection = true;
+ else if (!lstrcmp(nm, TEXT("no")))
+ _svp._rightClickKeepsSelection = false;
+ }
+
// Disable Advanced Scrolling
nm = element->Attribute(TEXT("disableAdvancedScrolling"));
if (nm)
@@ -5494,6 +5504,7 @@ bool NppParameters::writeScintillaParams()
(scintNode->ToElement())->SetAttribute(TEXT("currentLineHilitingShow"), _svp._currentLineHilitingShow?TEXT("show"):TEXT("hide"));
(scintNode->ToElement())->SetAttribute(TEXT("scrollBeyondLastLine"), _svp._scrollBeyondLastLine?TEXT("yes"):TEXT("no"));
+ (scintNode->ToElement())->SetAttribute(TEXT("rightClickKeepsSelection"), _svp._rightClickKeepsSelection ? TEXT("yes") : TEXT("no"));
(scintNode->ToElement())->SetAttribute(TEXT("disableAdvancedScrolling"), _svp._disableAdvancedScrolling?TEXT("yes"):TEXT("no"));
(scintNode->ToElement())->SetAttribute(TEXT("wrapSymbolShow"), _svp._wrapSymbolShow?TEXT("show"):TEXT("hide"));
(scintNode->ToElement())->SetAttribute(TEXT("Wrap"), _svp._doWrap?TEXT("yes"):TEXT("no"));
@@ -5965,7 +5976,7 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._commandLineInterpreter.c_str()));
}
- //
+ //
writeScintillaParams();
//
diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h
index 490894412..67a043426 100644
--- a/PowerEditor/src/Parameters.h
+++ b/PowerEditor/src/Parameters.h
@@ -931,6 +931,7 @@ struct ScintillaViewParams
bool _eolShow = false;
int _borderWidth = 2;
bool _scrollBeyondLastLine = false;
+ bool _rightClickKeepsSelection = false;
bool _disableAdvancedScrolling = false;
bool _doSmoothFont = false;
bool _showBorderEdge = true;
diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp
index 8e5d1c28a..55522cfe8 100644
--- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp
+++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
#include "ScintillaEditView.h"
#include "Parameters.h"
#include "Sorters.h"
@@ -513,6 +514,25 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
{
break;
}
+
+ case WM_RBUTTONDOWN:
+ {
+ bool rightClickKeepsSelection = ((NppParameters::getInstance()).getSVP())._rightClickKeepsSelection;
+ if (rightClickKeepsSelection)
+ {
+ int clickX = GET_X_LPARAM(lParam);
+ int marginX = static_cast(execute(SCI_POINTXFROMPOSITION, 0, 0));
+ if (clickX >= marginX)
+ {
+ // if right-click in the editing area (not the margins!),
+ // don't let this go to Scintilla because it will
+ // move the caret to the right-clicked location,
+ // cancelling any selection made by the user
+ return TRUE;
+ }
+ }
+ break;
+ }
}
return _callWindowProc(_scintillaDefaultProc, hwnd, Message, wParam, lParam);
}
diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc
index 05467f60e..ec5a2b87d 100644
--- a/PowerEditor/src/WinControls/Preference/preference.rc
+++ b/PowerEditor/src/WinControls/Preference/preference.rc
@@ -104,12 +104,13 @@ BEGIN
CONTROL "",IDC_BORDERWIDTH_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,48,148,67,13
LTEXT "0",IDC_BORDERWIDTHVAL_STATIC,116,148,12,8
CONTROL "No edge",IDC_CHECK_NOEDGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,165,60,10
- CONTROL "Display line number",IDC_CHECK_LINENUMBERMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,107,141,10
- CONTROL "Display bookmark",IDC_CHECK_BOOKMARKMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,120,150,10
- CONTROL "Enable current line highlighting",IDC_CHECK_CURRENTLINEHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,133,129,10
- CONTROL "Enable smooth font",IDC_CHECK_SMOOTHFONT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,146,129,10
- CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,159,139,10
- CONTROL "Disable advanced scrolling feature\r(if you have touchpad problem)",IDC_CHECK_DISABLEADVANCEDSCROLL,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,298,172,139,18
+ CONTROL "Display line number",IDC_CHECK_LINENUMBERMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,106,141,10
+ CONTROL "Display bookmark",IDC_CHECK_BOOKMARKMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,118,150,10
+ CONTROL "Enable current line highlighting",IDC_CHECK_CURRENTLINEHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,130,129,10
+ CONTROL "Enable smooth font",IDC_CHECK_SMOOTHFONT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,142,129,10
+ CONTROL "Enable scrolling beyond last line",IDC_CHECK_SCROLLBEYONDLASTLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,298,154,139,10
+ CONTROL "Keep selection when right-click outside of selection",IDC_CHECK_RIGHTCLICKKEEPSSELECTION,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,298,165,139,18
+ CONTROL "Disable advanced scrolling feature\r(if you have touchpad problem)",IDC_CHECK_DISABLEADVANCEDSCROLL,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,298,184,139,18
END
IDD_PREFERENCE_SETTING_BOX DIALOGEX 0, 0, 455, 185
diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
index c8d031804..3c42898a2 100644
--- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
+++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
@@ -644,6 +644,7 @@ void MarginsDlg::initScintParam()
::SendDlgItemMessage(_hSelf, IDC_CHECK_BOOKMARKMARGE, BM_SETCHECK, svp._bookMarkMarginShow, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_CURRENTLINEHILITE, BM_SETCHECK, svp._currentLineHilitingShow, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_SCROLLBEYONDLASTLINE, BM_SETCHECK, svp._scrollBeyondLastLine, 0);
+ ::SendDlgItemMessage(_hSelf, IDC_CHECK_RIGHTCLICKKEEPSSELECTION, BM_SETCHECK, svp._rightClickKeepsSelection, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_DISABLEADVANCEDSCROLL, BM_SETCHECK, svp._disableAdvancedScrolling, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_NOEDGE, BM_SETCHECK, !svp._showBorderEdge, 0);
@@ -765,6 +766,10 @@ INT_PTR CALLBACK MarginsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPa
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SCROLLBEYONDLASTLINE, 0, 0);
return TRUE;
+ case IDC_CHECK_RIGHTCLICKKEEPSSELECTION:
+ svp._rightClickKeepsSelection = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_RIGHTCLICKKEEPSSELECTION, BM_GETCHECK, 0, 0));
+ return TRUE;
+
case IDC_CHECK_DISABLEADVANCEDSCROLL:
svp._disableAdvancedScrolling = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_DISABLEADVANCEDSCROLL, BM_GETCHECK, 0, 0));
return TRUE;
diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h
index d42fac4de..4cee9e454 100644
--- a/PowerEditor/src/WinControls/Preference/preference_rc.h
+++ b/PowerEditor/src/WinControls/Preference/preference_rc.h
@@ -125,6 +125,7 @@
#define IDC_STATIC_MULTILNMODE_TIP (IDD_PREFERENCE_MARGEIN_BOX + 37)
#define IDC_COLUMNPOS_EDIT (IDD_PREFERENCE_MARGEIN_BOX + 38)
+ #define IDC_CHECK_RIGHTCLICKKEEPSSELECTION (IDD_PREFERENCE_MARGEIN_BOX + 39)
#define IDD_PREFERENCE_DELIMITERSETTINGS_BOX 6250 //(IDD_PREFERENCE_BOX + 250)
#define IDC_DELIMITERSETTINGS_GB_STATIC (IDD_PREFERENCE_DELIMITERSETTINGS_BOX + 1)