From 7569ff93c77d503aa2a7e68c81789510d0d7e95e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sun, 10 Sep 2017 10:20:17 +0200 Subject: [PATCH] + add new Settings "Virtual Space on Rectangular Selection" used to select rectange not delemited by line endings (but including virtual space) --- src/Edit.c | 3 ++- src/Notepad3.c | 41 +++++++++++++++++++++++++++++++++-------- src/Notepad3.h | 1 + src/Notepad3.rc | Bin 181404 -> 181666 bytes src/resource.h | 1 + 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index c31f1a6f2..b2a9a3641 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -74,6 +74,7 @@ extern BOOL bLoadASCIIasUTF8; extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; +extern BOOL bVirtualSpaceInRectSelection; extern int iMarkOccurrencesMaxCount; #define DELIM_BUFFER 258 @@ -289,7 +290,7 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_SETYCARETPOLICY,CARET_EVEN,0); SendMessage(hwnd,SCI_SETMULTIPLESELECTION,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALSELECTIONTYPING,FALSE,0); - SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS,SCVS_NONE,0); + SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS,(bVirtualSpaceInRectSelection ? SCVS_RECTANGULARSELECTION : SCVS_NONE),0); SendMessage(hwnd,SCI_SETADDITIONALCARETSBLINK,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALCARETSVISIBLE,FALSE,0); diff --git a/src/Notepad3.c b/src/Notepad3.c index 48b01acd1..fb8470d16 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -152,6 +152,7 @@ BOOL bMarkOccurrencesMatchCase; BOOL bMarkOccurrencesMatchWords; BOOL bAutoCompleteWords; BOOL bAccelWordNavigation; +BOOL bVirtualSpaceInRectSelection; BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; @@ -2358,6 +2359,7 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) EnableCmd(hmenu,IDM_EDIT_COMPLETEWORD,i); CheckCmd(hmenu,IDM_VIEW_AUTOCOMPLETEWORDS,bAutoCompleteWords); CheckCmd(hmenu,IDM_VIEW_ACCELWORDNAV,bAccelWordNavigation); + CheckCmd(hmenu,IDM_VIEW_VIRTSPACERECTSEL,bVirtualSpaceInRectSelection); switch (iMarkOccurrences) { @@ -4199,12 +4201,19 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) SendMessage(hwndEdit, SCI_AUTOCCANCEL, 0, 0); // close the auto completion list break; - case IDM_VIEW_ACCELWORDNAV: + case IDM_VIEW_ACCELWORDNAV: bAccelWordNavigation = (bAccelWordNavigation) ? FALSE : TRUE; // toggle EditSetAccelWordNav(hwndEdit,bAccelWordNavigation); EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; + case IDM_VIEW_VIRTSPACERECTSEL: + bVirtualSpaceInRectSelection = (bVirtualSpaceInRectSelection) ? FALSE : TRUE; // toggle + //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); + SendMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS, + (bVirtualSpaceInRectSelection ? SCVS_RECTANGULARSELECTION : SCVS_NONE),0); + break; + case IDM_VIEW_MARKOCCURRENCES_OFF: iMarkOccurrences = 0; // clear all marks @@ -5842,6 +5851,9 @@ void LoadSettings() bAccelWordNavigation = IniSectionGetInt(pIniSection, L"AccelWordNavigation", 0); if (bAccelWordNavigation) bAccelWordNavigation = 1; + bVirtualSpaceInRectSelection = IniSectionGetInt(pIniSection,L"VirtualSpaceInRectSelection",0); + if (bVirtualSpaceInRectSelection) bVirtualSpaceInRectSelection = 1; + bShowIndentGuides = IniSectionGetInt(pIniSection,L"ShowIndentGuides",0); if (bShowIndentGuides) bShowIndentGuides = 1; @@ -6175,6 +6187,7 @@ void SaveSettings(BOOL bSaveSettingsNow) { IniSectionSetInt(pIniSection, L"AutoIndent", bAutoIndent); IniSectionSetInt(pIniSection, L"AutoCompleteWords", bAutoCompleteWords); IniSectionSetInt(pIniSection, L"AccelWordNavigation", bAccelWordNavigation); + IniSectionSetInt(pIniSection, L"VirtualSpaceInRectSelection",bVirtualSpaceInRectSelection); IniSectionSetInt(pIniSection, L"ShowIndentGuides", bShowIndentGuides); IniSectionSetInt(pIniSection, L"TabsAsSpaces", bTabsAsSpacesG); IniSectionSetInt(pIniSection, L"TabIndents", bTabIndentsG); @@ -7168,13 +7181,19 @@ void InvalidateSelections() int BeginSelUndoAction() { int token = -1; - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0 }; sel.selMode = (int)SendMessage(hwndEdit,SCI_GETSELECTIONMODE,0,0); + sel.rectSelVS = (int)SendMessage(hwndEdit,SCI_GETVIRTUALSPACEOPTIONS,0,0); if (sel.selMode == SC_SEL_LINES) { sel.anchorPos_undo = (int)SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0); sel.currPos_undo = (int)SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0); } - else { + else if (sel.selMode == SC_SEL_RECTANGLE) { + sel.anchorPos_undo = (int)SendMessage(hwndEdit,SCI_GETRECTANGULARSELECTIONANCHOR,0,0); + sel.currPos_undo = (int)SendMessage(hwndEdit,SCI_GETRECTANGULARSELECTIONCARET,0,0); + } + else + { sel.anchorPos_undo = (int)SendMessage(hwndEdit,SCI_GETANCHOR,0,0); sel.currPos_undo = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0); } @@ -7196,13 +7215,17 @@ int BeginSelUndoAction() void EndSelUndoAction(int token) { if (token >= 0) { - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0 }; if (UndoRedoSelectionMap(token,&sel) >= 0) { - // mode should not have changed ??? + // mode and type should not have changed if (sel.selMode == SC_SEL_LINES) { sel.anchorPos_redo = (int)SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0); sel.currPos_redo = (int)SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0); } + else if (sel.selMode == SC_SEL_RECTANGLE) { + sel.anchorPos_redo = (int)SendMessage(hwndEdit,SCI_GETRECTANGULARSELECTIONANCHOR,0,0); + sel.currPos_redo = (int)SendMessage(hwndEdit,SCI_GETRECTANGULARSELECTIONCARET,0,0); + } else { sel.anchorPos_redo = (int)SendMessage(hwndEdit,SCI_GETANCHOR,0,0); sel.currPos_redo = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0); @@ -7222,12 +7245,14 @@ void EndSelUndoAction(int token) // void RestoreSelectionAction(int token, DoAction doAct) { - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0 }; if (UndoRedoSelectionMap(token,&sel) >= 0) { // we are inside undo/redo transaction, so do delayed PostMessage() instead of SendMessage() int anchorPos = (doAct == UNDO ? sel.anchorPos_undo : sel.anchorPos_redo); int currPos = (doAct == UNDO ? sel.currPos_undo : sel.currPos_redo); - SendMessage(hwndEdit,SCI_SETSELECTIONMODE,(WPARAM)sel.selMode,0); + int currRectType = (int)SendMessage(hwndEdit,SCI_GETVIRTUALSPACEOPTIONS,0,0); + PostMessage(hwndEdit,SCI_SETSELECTIONMODE,(WPARAM)sel.selMode,0); + PostMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)sel.rectSelVS,0); if (sel.selMode == SC_SEL_LINES) { PostMessage(hwndEdit,SCI_SETSELECTIONSTART,(WPARAM)anchorPos,0); PostMessage(hwndEdit,SCI_SETSELECTIONEND,(WPARAM)currPos,0); @@ -7239,7 +7264,7 @@ void RestoreSelectionAction(int token, DoAction doAct) else { PostMessage(hwndEdit,SCI_SETSELECTION,(WPARAM)currPos,(LPARAM)anchorPos); } - + PostMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0); PostMessage(hwndEdit,SCI_CANCEL,0,0); } } diff --git a/src/Notepad3.h b/src/Notepad3.h index a4751c025..64e7932d1 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -48,6 +48,7 @@ typedef struct _undoSel int currPos_undo; int anchorPos_redo; int currPos_redo; + int rectSelVS; } UndoRedoSelection_t; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index faf54982c8f5a97044685512d4de5da0848bf3a8..9abf97885a8a9afa5bd460490f8f884c38774cbe 100644 GIT binary patch delta 194 zcmbQ!$-StXd&7t7$pONAlLdN2CbQI3O@3!1HhIBRp6Sy*GKx&*>(iKguEqweV8Sew z$$GU#VD^G-N|TSg5&+Bh)NxH_sWY0K(5kT6qfU+y#F$)B-!?f!NNn+GCL4%aP2Nz#);y)LeM%$a K_9=}_d@cYW`Y{Cn diff --git a/src/resource.h b/src/resource.h index 94c1ffa99..173a4f464 100644 --- a/src/resource.h +++ b/src/resource.h @@ -380,6 +380,7 @@ #define IDM_VIEW_MARKOCCURRENCES_WORD 40452 #define IDM_VIEW_AUTOCOMPLETEWORDS 40453 #define IDM_VIEW_ACCELWORDNAV 40454 +#define IDM_VIEW_VIRTSPACERECTSEL 40455 #define IDM_HELP_ABOUT 40500 #define IDM_HELP_CMD 40501 #define IDM_TRAY_RESTORE 40600