Add an option to prevent right-click from canceling selection

Fix #8563, close  #8564
pull/8685/head
Scott Sumner 2020-07-14 20:12:20 -04:00 committed by Don HO
parent 5ba7f99590
commit f1b059414b
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
7 changed files with 47 additions and 7 deletions

View File

@ -756,6 +756,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6231" name="Border Width"/>
<Item id="6235" name="No edge"/>
<Item id="6236" name="Enable scrolling beyond last line"/>
<Item id="6239" name="Keep selection when right-click outside of selection"/>
</Scintillas>
<NewDoc title="New Document">

View File

@ -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()));
}
// <GUIConfig name="ScintillaPrimaryView" lineNumberMargin="show" bookMarkMargin="show" indentGuideLine="show" folderMarkStyle="box" lineWrapMethod="aligned" currentLineHilitingShow="show" scrollBeyondLastLine="no" disableAdvancedScrolling="no" wrapSymbolShow="hide" Wrap="no" borderEdge="yes" edge="no" edgeNbColumn="80" zoom="0" zoom2="0" whiteSpaceShow="hide" eolShow="hide" borderWidth="2" smoothFont="no" />
// <GUIConfig name="ScintillaPrimaryView" lineNumberMargin="show" bookMarkMargin="show" indentGuideLine="show" folderMarkStyle="box" lineWrapMethod="aligned" currentLineHilitingShow="show" scrollBeyondLastLine="no" rightClickKeepsSelection="no" disableAdvancedScrolling="no" wrapSymbolShow="hide" Wrap="no" borderEdge="yes" edge="no" edgeNbColumn="80" zoom="0" zoom2="0" whiteSpaceShow="hide" eolShow="hide" borderWidth="2" smoothFont="no" />
writeScintillaParams();
// <GUIConfig name="DockingManager" leftWidth="328" rightWidth="359" topHeight="200" bottomHeight="436">

View File

@ -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;

View File

@ -28,6 +28,7 @@
#include <memory>
#include <shlwapi.h>
#include <cinttypes>
#include <windowsx.h>
#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<int>(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);
}

View File

@ -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

View File

@ -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;

View File

@ -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)