From 774e72b9f2736a255586b3a68c7d0589544eaeea Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 19 Oct 2017 12:32:57 +0200 Subject: [PATCH 1/7] + applying patch from Neil Hodgson (Master of Scintilla Lib - respond to scintilla lib issue report #1976) --- scintilla/src/EditView.cxx | 19 +++++++++++++++++-- scintilla/src/EditView.h | 1 + scintilla/src/Editor.cxx | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 162a86425..c618667d0 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -643,6 +643,19 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci:: return rangeSubLine; } +XYPOSITION EditView::EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line) { + int styleEnd = ll->EndLineStyle(); + const bool bracesIgnoreStyle = ((vs.braceHighlightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACELIGHT)) || + (vs.braceBadLightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACEBAD))); + if (!bracesIgnoreStyle) { + const Sci::Position lineLastCharacter = static_cast(model.pdoc->LineEnd(line)) - 1; + if ((lineLastCharacter == model.braces[0]) || (lineLastCharacter == model.braces[1])) { + styleEnd = model.bracesMatchStyle; + } + } + return vs.styles[styleEnd].spaceWidth; +} + SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { pt.x = pt.x - vs.textStart; Sci::Line visibleLine = static_cast(floor(pt.y / vs.lineHeight)); @@ -671,7 +684,8 @@ SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditMo return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } if (virtualSpace) { - const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; + //@@@const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; + const XYPOSITION spaceWidth = EndSpaceWidth(model, vs, ll, lineDoc); const int spaceOffset = static_cast( (pt.x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); @@ -705,7 +719,8 @@ SelectionPosition EditView::SPositionFromLineX(Surface *surface, const EditModel if (positionInLine < rangeSubLine.end) { return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } - const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; + //@@@const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; + const XYPOSITION spaceWidth = EndSpaceWidth(model, vs, ll, lineDoc); const int spaceOffset = static_cast( (x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); diff --git a/scintilla/src/EditView.h b/scintilla/src/EditView.h index a842ac63a..f91841b1e 100644 --- a/scintilla/src/EditView.h +++ b/scintilla/src/EditView.h @@ -117,6 +117,7 @@ public: Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine, const ViewStyle &vs, PointEnd pe); Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs); + XYPOSITION EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line); SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs); SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index dde6c7ebc..45edc81f8 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -5131,6 +5131,7 @@ void Editor::SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int match Redraw(); } } + SetRectangularRange(); } void Editor::SetAnnotationHeights(Sci::Line start, Sci::Line end) { From d0c7fbc8efb69b955a09b1fd9deb066a57dcbd20 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 19 Oct 2017 16:21:03 +0200 Subject: [PATCH 2/7] + prepare new matching brace highlighting (SCI_BRACEHIGHLIGHTINDICATOR API...) --- src/Edit.c | 83 +++++++++++++++++++++++++++++++++++++++++++++----- src/Edit.h | 7 ++++- src/Notepad3.c | 83 +++++++++++--------------------------------------- 3 files changed, 99 insertions(+), 74 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 72ecf7e82..363c03042 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -48,7 +48,6 @@ #define DEFAULT_SCROLL_WIDTH 4096 // 4K - extern HWND hwndMain; extern HWND hwndEdit; extern HINSTANCE g_hInstance; @@ -78,6 +77,8 @@ extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; extern BOOL bVirtualSpaceInRectSelection; + +extern int iMarkOccurrences; extern int iMarkOccurrencesCount; extern int iMarkOccurrencesMaxCount; @@ -171,6 +172,12 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_HOME + (SCMOD_SHIFT << 16)),SCI_VCHOMEWRAPEXTEND); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_END + (SCMOD_SHIFT << 16)),SCI_LINEENDWRAPEXTEND); + // set style + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MARK_OCCURANCE, 100); + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MARK_OCCURANCE, INDIC_ROUNDBOX); + + // word delimiter handling EditInitWordDelimiter(hwnd); EditSetAccelWordNav(hwnd,bAccelWordNavigation); @@ -5237,12 +5244,77 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) LocalFree(pRoot); } + +//============================================================================= +// +// EditMatchBrace() +// +void EditMatchBrace(HWND hwnd) +{ + // set style + //SendMessage(hwnd, SCI_INDICSETALPHA, 1, 100); + //SendMessage(hwnd, SCI_INDICSETFORE, 1, 0xff << ((iMarkOccurrences - 1) << 3)); + //SendMessage(hwnd, SCI_INDICSETSTYLE, 1, INDIC_ROUNDBOX); + //SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, 0); + //SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, 0); + + int iPos; + char c; + + int iEndStyled = (int)SendMessage(hwnd, SCI_GETENDSTYLED, 0, 0); + if (iEndStyled < (int)SendMessage(hwnd, SCI_GETLENGTH, 0, 0)) { + int iLine = (int)SendMessage(hwnd, SCI_LINEFROMPOSITION, iEndStyled, 0); + int iEndStyled2 = (int)SendMessage(hwnd, SCI_POSITIONFROMLINE, iLine, 0); + SendMessage(hwnd, SCI_COLOURISE, iEndStyled2, -1); + } + + iPos = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); + c = (char)SendMessage(hwnd, SCI_GETCHARAT, iPos, 0); + if (StrChrA("()[]{}", c)) { + int iBrace2 = (int)SendMessage(hwnd, SCI_BRACEMATCH, iPos, 0); + if (iBrace2 != -1) { + int col1 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iPos, 0); + int col2 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iBrace2, 0); + SendMessage(hwnd, SCI_BRACEHIGHLIGHT, iPos, iBrace2); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, min(col1, col2), 0); + } + else { + SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); + } + } + // Try one before + else { + iPos = (int)SendMessage(hwnd, SCI_POSITIONBEFORE, iPos, 0); + c = (char)SendMessage(hwnd, SCI_GETCHARAT, iPos, 0); + if (StrChrA("()[]{}", c)) { + int iBrace2 = (int)SendMessage(hwnd, SCI_BRACEMATCH, iPos, 0); + if (iBrace2 != -1) { + int col1 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iPos, 0); + int col2 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iBrace2, 0); + SendMessage(hwnd, SCI_BRACEHIGHLIGHT, iPos, iBrace2); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, min(col1, col2), 0); + } + else { + SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); + } + } + else { + SendMessage(hwnd, SCI_BRACEHIGHLIGHT, (WPARAM)-1, (LPARAM)-1); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); + } + } +} + + + //============================================================================= // // EditMarkAll() // Mark all occurrences of the text currently selected (by Aleksandar Lekov) // -void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase, BOOL bMarkOccurrencesMatchWords) +void EditMarkAll(HWND hwnd, BOOL bMarkOccurrencesMatchCase, BOOL bMarkOccurrencesMatchWords) { struct Sci_TextToFind ttf; int iPos; @@ -5270,7 +5342,7 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase iSelCount = iSelEnd - iSelStart; // clear existing indicator - SendMessage(hwnd, SCI_SETINDICATORCURRENT, 1, 0); + SendMessage(hwnd, SCI_SETINDICATORCURRENT, INDIC_NP3_MARK_OCCURANCE, 0); SendMessage(hwnd, SCI_INDICATORCLEARRANGE, 0, iTextLen); // if nothing selected or multiple lines are selected exit @@ -5306,11 +5378,6 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase ttf.chrg.cpMax = iTextLen; ttf.lpstrText = pszText; - // set style - SendMessage(hwnd, SCI_INDICSETALPHA, 1, 100); - SendMessage(hwnd, SCI_INDICSETFORE, 1, 0xff << ((iMarkOccurrences - 1) << 3)); - SendMessage(hwnd, SCI_INDICSETSTYLE, 1, INDIC_ROUNDBOX); - iMarkOccurrencesCount = 0; while ((iPos = (int)SendMessage(hwnd, SCI_FINDTEXT, (bMarkOccurrencesMatchCase ? SCFIND_MATCHCASE : 0) | (bMarkOccurrencesMatchWords ? SCFIND_WHOLEWORD : 0), diff --git a/src/Edit.h b/src/Edit.h index 321b07f6f..a9b7ddaa6 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -44,6 +44,10 @@ typedef struct _editfindreplace #define IDMSG_SWITCHTOFIND 300 #define IDMSG_SWITCHTOREPLACE 301 + +#define INDIC_NP3_MARK_OCCURANCE 1 +#define INDIC_NP3_MATCH_BRACE 2 + HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); void EditSetNewText(HWND,char*,DWORD); @@ -108,7 +112,8 @@ BOOL EditAlignDlg(HWND,int*); BOOL EditPrint(HWND,LPCWSTR,LPCWSTR); void EditPrintSetup(HWND); void EditPrintInit(); -void EditMarkAll(HWND,int,BOOL,BOOL); +void EditMatchBrace(HWND); +void EditMarkAll(HWND,BOOL,BOOL); void EditSetAccelWordNav(HWND,BOOL); void CompleteWord(HWND,BOOL); diff --git a/src/Notepad3.c b/src/Notepad3.c index 8fd474239..623127b39 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -4222,7 +4222,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_ACCELWORDNAV: bAccelWordNavigation = (bAccelWordNavigation) ? FALSE : TRUE; // toggle EditSetAccelWordNav(hwndEdit,bAccelWordNavigation); - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_VIRTSPACERECTSEL: @@ -4235,33 +4235,36 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_MARKOCCURRENCES_OFF: iMarkOccurrences = 0; // clear all marks - SendMessage(hwndEdit, SCI_SETINDICATORCURRENT, 1, 0); + SendMessage(hwndEdit, SCI_SETINDICATORCURRENT, INDIC_NP3_MARK_OCCURANCE, 0); SendMessage(hwndEdit, SCI_INDICATORCLEARRANGE, 0, (int)SendMessage(hwndEdit,SCI_GETLENGTH,0,0)); break; case IDM_VIEW_MARKOCCURRENCES_RED: iMarkOccurrences = 1; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_GREEN: iMarkOccurrences = 2; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_BLUE: iMarkOccurrences = 3; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_CASE: bMarkOccurrencesMatchCase = (bMarkOccurrencesMatchCase) ? FALSE : TRUE; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_WORD: bMarkOccurrencesMatchWords = (bMarkOccurrencesMatchWords) ? FALSE : TRUE; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_FOLDING: @@ -5406,69 +5409,19 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) switch(pnmh->code) { case SCN_UPDATEUI: - - if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) { - - UpdateStatusbar(); - UpdateToolbar(); - + if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) + { InvalidateSelections(); // mark occurrences of text currently selected - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); // Brace Match - if (bMatchBraces) - { - int iPos; - char c; - - int iEndStyled = (int)SendMessage(hwndEdit,SCI_GETENDSTYLED,0,0); - if (iEndStyled < (int)SendMessage(hwndEdit,SCI_GETLENGTH,0,0)) { - int iLine = (int)SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iEndStyled,0); - int iEndStyled2 = (int)SendMessage(hwndEdit,SCI_POSITIONFROMLINE,iLine,0); - SendMessage(hwndEdit,SCI_COLOURISE,iEndStyled2,-1); - } - - iPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0); - c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0); - if (StrChrA("()[]{}",c)) { - int iBrace2 = (int)SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0); - if (iBrace2 != -1) { - int col1 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iPos,0); - int col2 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iBrace2,0); - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,iPos,iBrace2); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,min(col1,col2),0); - } - else { - SendMessage(hwndEdit,SCI_BRACEBADLIGHT,iPos,0); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } - // Try one before - else - { - iPos = (int)SendMessage(hwndEdit,SCI_POSITIONBEFORE,iPos,0); - c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0); - if (StrChrA("()[]{}",c)) { - int iBrace2 = (int)SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0); - if (iBrace2 != -1) { - int col1 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iPos,0); - int col2 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iBrace2,0); - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,iPos,iBrace2); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,min(col1,col2),0); - } - else { - SendMessage(hwndEdit,SCI_BRACEBADLIGHT,iPos,0); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } - else { - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,(WPARAM)-1,(LPARAM)-1); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } + if (bMatchBraces) { + EditMatchBrace(hwndEdit); } + UpdateToolbar(); + UpdateStatusbar(); } break; @@ -7418,7 +7371,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp iFileWatchingMode = 0; InstallFileWatching(NULL); bEnableSaveSettings = TRUE; - UpdateSettingsCmds(hwndMain); + UpdateSettingsCmds(); return TRUE; } From 5a34995f96df42ef1ece9def3a341b3b457401c2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 19 Oct 2017 23:03:39 +0200 Subject: [PATCH 3/7] + wrap Neil's patch by NP3_MATCH_BRACE_RECT_SEL_PATCH define, to switch patch on/off --- scintilla/src/EditView.cxx | 18 ++++++++++++++---- scintilla/src/EditView.h | 6 +++++- scintilla/src/Editor.cxx | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index c618667d0..a631f5cfc 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -643,6 +643,8 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci:: return rangeSubLine; } +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + XYPOSITION EditView::EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line) { int styleEnd = ll->EndLineStyle(); const bool bracesIgnoreStyle = ((vs.braceHighlightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACELIGHT)) || @@ -655,6 +657,8 @@ XYPOSITION EditView::EndSpaceWidth(const EditModel &model, const ViewStyle &vs, } return vs.styles[styleEnd].spaceWidth; } +#endif + SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { pt.x = pt.x - vs.textStart; @@ -684,8 +688,11 @@ SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditMo return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } if (virtualSpace) { - //@@@const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION spaceWidth = EndSpaceWidth(model, vs, ll, lineDoc); +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + const XYPOSITION spaceWidth = EndSpaceWidth(model,vs,ll,lineDoc); +#else + const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#endif const int spaceOffset = static_cast( (pt.x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); @@ -719,8 +726,11 @@ SelectionPosition EditView::SPositionFromLineX(Surface *surface, const EditModel if (positionInLine < rangeSubLine.end) { return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } - //@@@const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; - const XYPOSITION spaceWidth = EndSpaceWidth(model, vs, ll, lineDoc); +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + const XYPOSITION spaceWidth = EndSpaceWidth(model,vs,ll,lineDoc); +#else + const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#endif const int spaceOffset = static_cast( (x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); diff --git a/scintilla/src/EditView.h b/scintilla/src/EditView.h index f91841b1e..1610ae928 100644 --- a/scintilla/src/EditView.h +++ b/scintilla/src/EditView.h @@ -12,6 +12,8 @@ namespace Scintilla { #endif +#define NP3_MATCH_BRACE_RECT_SEL_PATCH 1 + struct PrintParameters { int magnification; int colourMode; @@ -117,8 +119,10 @@ public: Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine, const ViewStyle &vs, PointEnd pe); Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs); +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH XYPOSITION EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line); - SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, +#endif + SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs); SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs); Sci::Line DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 45edc81f8..b4472b6a9 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -5131,7 +5131,9 @@ void Editor::SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int match Redraw(); } } - SetRectangularRange(); +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + SetRectangularRange(); +#endif } void Editor::SetAnnotationHeights(Sci::Line start, Sci::Line end) { From 2c9f47950afab750eb2f97f126900cb2cddecb79 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 20 Oct 2017 00:49:20 +0200 Subject: [PATCH 4/7] - revert Neil's proposed patch and rely on Scintilla upstream decision for next revision + switch to SCI_BRACEHIGHLIGHTINDICATOR API (following Neil's recomendation) --- scintilla/src/EditView.h | 2 +- src/Edit.c | 25 ++++++++++----- src/Edit.h | 1 + src/Styles.c | 67 +++++++++++++++++++++++----------------- 4 files changed, 57 insertions(+), 38 deletions(-) diff --git a/scintilla/src/EditView.h b/scintilla/src/EditView.h index 1610ae928..3f2a9042f 100644 --- a/scintilla/src/EditView.h +++ b/scintilla/src/EditView.h @@ -12,7 +12,7 @@ namespace Scintilla { #endif -#define NP3_MATCH_BRACE_RECT_SEL_PATCH 1 +#undef NP3_MATCH_BRACE_RECT_SEL_PATCH struct PrintParameters { int magnification; diff --git a/src/Edit.c b/src/Edit.c index 363c03042..c7e5c599f 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -172,11 +172,22 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_HOME + (SCMOD_SHIFT << 16)),SCI_VCHOMEWRAPEXTEND); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_END + (SCMOD_SHIFT << 16)),SCI_LINEENDWRAPEXTEND); - // set style + // set indicator styles + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_MARK_OCCURANCE, 220); SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MARK_OCCURANCE, 100); SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MARK_OCCURANCE, INDIC_ROUNDBOX); + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, 220); + SendMessage(hwnd, SCI_INDICSETALPHA,INDIC_NP3_MATCH_BRACE, 120); + SendMessage(hwnd, SCI_INDICSETFORE,INDIC_NP3_MATCH_BRACE, 0xff << (1 << 3)); // overriden by style + SendMessage(hwnd, SCI_INDICSETSTYLE,INDIC_NP3_MATCH_BRACE, INDIC_FULLBOX); + + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, 220); + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, 120); + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_BAD_BRACE, 0xff ); // overriden by style + SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_BAD_BRACE, INDIC_FULLBOX); + // word delimiter handling EditInitWordDelimiter(hwnd); @@ -5251,13 +5262,6 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) // void EditMatchBrace(HWND hwnd) { - // set style - //SendMessage(hwnd, SCI_INDICSETALPHA, 1, 100); - //SendMessage(hwnd, SCI_INDICSETFORE, 1, 0xff << ((iMarkOccurrences - 1) << 3)); - //SendMessage(hwnd, SCI_INDICSETSTYLE, 1, INDIC_ROUNDBOX); - //SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, 0); - //SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, 0); - int iPos; char c; @@ -5276,10 +5280,12 @@ void EditMatchBrace(HWND hwnd) int col1 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iPos, 0); int col2 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iBrace2, 0); SendMessage(hwnd, SCI_BRACEHIGHLIGHT, iPos, iBrace2); + SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, INDIC_NP3_MATCH_BRACE); SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, min(col1, col2), 0); } else { SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0); + SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, INDIC_NP3_BAD_BRACE); SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); } } @@ -5293,15 +5299,18 @@ void EditMatchBrace(HWND hwnd) int col1 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iPos, 0); int col2 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iBrace2, 0); SendMessage(hwnd, SCI_BRACEHIGHLIGHT, iPos, iBrace2); + SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, INDIC_NP3_MATCH_BRACE); SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, min(col1, col2), 0); } else { SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0); + SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, INDIC_NP3_BAD_BRACE); SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); } } else { SendMessage(hwnd, SCI_BRACEHIGHLIGHT, (WPARAM)-1, (LPARAM)-1); + SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, INDIC_NP3_MATCH_BRACE); SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); } } diff --git a/src/Edit.h b/src/Edit.h index a9b7ddaa6..094691bc9 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -47,6 +47,7 @@ typedef struct _editfindreplace #define INDIC_NP3_MARK_OCCURANCE 1 #define INDIC_NP3_MATCH_BRACE 2 +#define INDIC_NP3_BAD_BRACE 3 HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); diff --git a/src/Styles.c b/src/Styles.c index ecf79093e..8f756612f 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -2998,8 +2998,20 @@ void Style_SetLexer(HWND hwnd,PEDITLEXER pLexNew) SendMessage(hwnd,SCI_STYLECLEARALL,0,0); Style_SetStyles(hwnd,lexDefault.Styles[1+iIdx].iStyle,lexDefault.Styles[1+iIdx].szValue); // linenumber - Style_SetStyles(hwnd,lexDefault.Styles[2+iIdx].iStyle,lexDefault.Styles[2+iIdx].szValue); // brace light - Style_SetStyles(hwnd,lexDefault.Styles[3+iIdx].iStyle,lexDefault.Styles[3+iIdx].szValue); // brace bad + + //~Style_SetStyles(hwnd,lexDefault.Styles[2+iIdx].iStyle,lexDefault.Styles[2+iIdx].szValue); // brace light + if (Style_StrGetColor(TRUE, lexDefault.Styles[2 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MATCH_BRACE, iValue); + if (Style_StrGetAlpha(lexDefault.Styles[2 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MATCH_BRACE, iValue); + + //~Style_SetStyles(hwnd,lexDefault.Styles[3+iIdx].iStyle,lexDefault.Styles[3+iIdx].szValue); // brace bad + if (Style_StrGetColor(TRUE, lexDefault.Styles[3 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_BAD_BRACE, iValue); + if (Style_StrGetAlpha(lexDefault.Styles[3 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, iValue); + + if (pLexNew != &lexANSI) Style_SetStyles(hwnd,lexDefault.Styles[4+iIdx].iStyle,lexDefault.Styles[4+iIdx].szValue); // control char Style_SetStyles(hwnd,lexDefault.Styles[5+iIdx].iStyle,lexDefault.Styles[5+iIdx].szValue); // indent guide @@ -3923,6 +3935,30 @@ BOOL Style_StrGetColor(BOOL bFore,LPCWSTR lpszStyle,int *rgb) } +//============================================================================= +// +// Style_StrGetAlpha() +// +BOOL Style_StrGetAlpha(LPCWSTR lpszStyle, int *i) { + WCHAR tch[256] = { L'\0' }; + WCHAR *p = StrStrI(lpszStyle, L"alpha:"); + if (p) { + StringCchCopy(tch, COUNTOF(tch), p + CSTRLEN(L"alpha:")); + p = StrChr(tch, L';'); + if (p) + *p = L'\0'; + TrimString(tch); + int iValue = 0; + int itok = swscanf_s(tch, L"%i", &iValue); + if (itok == 1) { + *i = min(max(SC_ALPHA_TRANSPARENT, iValue), SC_ALPHA_OPAQUE); + return TRUE; + } + } + return FALSE; +} + + //============================================================================= // // Style_StrGetCase() @@ -3951,33 +3987,6 @@ BOOL Style_StrGetCase(LPCWSTR lpszStyle,int *i) } -//============================================================================= -// -// Style_StrGetAlpha() -// -BOOL Style_StrGetAlpha(LPCWSTR lpszStyle,int *i) -{ - WCHAR tch[256] = { L'\0' }; - WCHAR *p = StrStrI(lpszStyle, L"alpha:"); - if (p) - { - StringCchCopy(tch,COUNTOF(tch),p + CSTRLEN(L"alpha:")); - p = StrChr(tch, L';'); - if (p) - *p = L'\0'; - TrimString(tch); - int iValue = 0; - int itok = swscanf_s(tch,L"%i",&iValue); - if (itok == 1) - { - *i = min(max(SC_ALPHA_TRANSPARENT,iValue),SC_ALPHA_OPAQUE); - return TRUE; - } - } - return FALSE; -} - - //============================================================================= // // Style_SelectFont() From cdecfb57568acd43daf906f8e398c03b9558aeca Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 20 Oct 2017 08:54:13 +0200 Subject: [PATCH 5/7] + add switch ([Settings2] UseOldStyleBraceMatching) to preserve old style brace matching behavior --- distrib/Notepad3.ini | Bin 2090 -> 2144 bytes doc/Notepad3.txt | 4 ++ src/Edit.c | 86 +++++++++++++++++++++---------------------- src/Helpers.h | 14 ++++--- src/Notepad3.c | 3 ++ src/Styles.c | 33 +++++++++++------ 6 files changed, 80 insertions(+), 60 deletions(-) diff --git a/distrib/Notepad3.ini b/distrib/Notepad3.ini index ea9752cf957c12f12f98fee7d7e8670cf20daa27..051fb93b5e01ae021fcd5d42a8f9ada3464605fe 100644 GIT binary patch delta 66 zcmZ1_@IYWg4Vz&oLoq`tgFizKLkdGMLkUAAkd?~d#8AYL$dC+V`2y(@AS;6*lOc~G RoxyhUMK Date: Fri, 20 Oct 2017 14:40:13 +0200 Subject: [PATCH 6/7] + first draft of "Alt-Key-Down Virtual Space Access" rectangular selection only (redo/undo action does not work properly yet?) --- src/Edit.c | 6 +-- src/Notepad3.c | 96 ++++++++++++++++++++++-------------------------- src/Notepad3.h | 1 - src/Notepad3.rc | Bin 182294 -> 182760 bytes src/resource.h | 3 +- 5 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 61756b984..30f764889 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -77,7 +77,6 @@ extern BOOL bLoadASCIIasUTF8; extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; -extern BOOL bVirtualSpaceInRectSelection; extern int iMarkOccurrences; extern int iMarkOccurrencesCount; @@ -158,12 +157,11 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_SETMOUSESELECTIONRECTANGULARSWITCH,TRUE,0); SendMessage(hwnd,SCI_SETMULTIPLESELECTION,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALSELECTIONTYPING,FALSE,0); - SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS, - (bVirtualSpaceInRectSelection ? (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE | SCVS_NOWRAPLINESTART) : SCVS_NONE),0); SendMessage(hwnd,SCI_SETADDITIONALCARETSBLINK,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALCARETSVISIBLE,FALSE,0); SendMessage(hwnd,SCI_SETMOUSEWHEELCAPTURES,FALSE,0); - + SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS,SCVS_NONE,0); + SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_NEXT + (SCMOD_CTRL << 16)),SCI_PARADOWN); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_PRIOR + (SCMOD_CTRL << 16)),SCI_PARAUP); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_NEXT + ((SCMOD_CTRL | SCMOD_SHIFT) << 16)),SCI_PARADOWNEXTEND); diff --git a/src/Notepad3.c b/src/Notepad3.c index 413f0d4df..79b4c8e43 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -67,6 +67,8 @@ HWND hDlgFindReplace = NULL; #define NUMINITIALTOOLS 24 #define MARGIN_FOLD_INDEX 2 +#define SCVS_NP3_SPACE_OPT (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE | SCVS_NOWRAPLINESTART) + TBBUTTON tbbMainWnd[] = { {0,IDT_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {1,IDT_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {2,IDT_FILE_BROWSE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, @@ -155,7 +157,7 @@ BOOL bMarkOccurrencesMatchWords; BOOL bUseOldStyleBraceMatching; BOOL bAutoCompleteWords; BOOL bAccelWordNavigation; -BOOL bVirtualSpaceInRectSelection; +BOOL bOldStyleRectSelection; BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; @@ -307,6 +309,7 @@ WCHAR g_wchWorkingDirectory[MAX_PATH+2] = { L'\0' }; // undo / redo selections +static BOOL bInUndoRedoAction = FALSE; static UT_icd UndoRedoSelection_icd = { sizeof(UndoRedoSelection_t), NULL, NULL, NULL }; static UT_array* UndoRedoSelectionUTArray = NULL; @@ -1146,11 +1149,29 @@ WININFO GetMyWindowPlacement(HWND hwnd,MONITORINFO* hMonitorInfo) // LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) { + if (!bOldStyleRectSelection && !bInUndoRedoAction) + { + BOOL bIsVSpaceAccessActive = (SendMessage(hwndEdit, SCI_GETVIRTUALSPACEOPTIONS, 0, 0) != SCVS_NONE); + if (GetAsyncKeyState(VK_MENU) & SHRT_MIN) // ALT DOWN + { + if (!bIsVSpaceAccessActive) { + //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); + } + } + else { + if (bIsVSpaceAccessActive) { + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NONE, 0); + } + } + } + switch(umsg) { // Quickly handle painting and sizing messages, found in ScintillaWin.cxx // Cool idea, don't know if this has any effect... ;-) case WM_MOVE: + case WM_MOUSEWHEEL: case WM_MOUSEACTIVATE: case WM_NCHITTEST: case WM_NCCALCSIZE: @@ -1166,7 +1187,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) case WM_CREATE: return MsgCreate(hwnd,wParam,lParam); - case WM_DESTROY: case WM_ENDSESSION: MsgEndSession(hwnd,umsg); @@ -1177,14 +1197,12 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) DestroyWindow(hwnd); break; - case WM_QUERYENDSESSION: if (FileSave(FALSE,TRUE,FALSE,FALSE)) return TRUE; else return FALSE; - // Reinitialize theme-dependent values and resize windows case WM_THEMECHANGED: MsgThemeChanged(hwnd,wParam,lParam); @@ -1199,16 +1217,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) return DefWindowProc(hwnd,umsg,wParam,lParam); } - //case WM_TIMER: // break; - case WM_SIZE: MsgSize(hwnd,wParam,lParam); break; - case WM_SETFOCUS: SetFocus(hwndEdit); @@ -1219,7 +1234,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) // PostMessage(hwnd,WM_CHANGENOTIFY,0,0); break; - case WM_DROPFILES: MsgDropFiles(hwnd, wParam, lParam); break; @@ -1235,13 +1249,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) MsgInitMenu(hwnd,wParam,lParam); break; - case WM_MOUSEWHEEL: - return DefWindowProc(hwnd,umsg,wParam,lParam); - case WM_NOTIFY: return MsgNotify(hwnd,wParam,lParam); - //case WM_PARENTNOTIFY: // if (LOWORD(wParam) & WM_DESTROY) { // if (IsWindow(hDlgFindReplace) && (hDlgFindReplace == (HWND)lParam)) { @@ -1250,7 +1260,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) // } // break; - case WM_COMMAND: return MsgCommand(hwnd,wParam,lParam); @@ -1261,13 +1270,11 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) MsgChangeNotify(hwnd, wParam, lParam); break; - //// This message is posted before Notepad3 reactivates itself //case WM_CHANGENOTIFYCLEAR: // bPendingChangeNotify = FALSE; // break; - case WM_DRAWCLIPBOARD: if (!bLastCopyFromMe) dwLastCopyTime = GetTickCount(); @@ -1278,7 +1285,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) SendMessage(hwndNextCBChain,WM_DRAWCLIPBOARD,wParam,lParam); break; - case WM_CHANGECBCHAIN: if ((HWND)wParam == hwndNextCBChain) hwndNextCBChain = (HWND)lParam; @@ -1286,11 +1292,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) SendMessage(hwndNextCBChain,WM_CHANGECBCHAIN,lParam,wParam); break; - case WM_TRAYMESSAGE: return MsgTrayMessage(hwnd, wParam, lParam); - default: if (umsg == msgTaskbarCreated) { if (!IsWindowVisible(hwnd)) @@ -1299,8 +1303,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) } return DefWindowProc(hwnd, umsg, wParam, lParam); } - - return 0; + return 0; // swallow message } @@ -2373,7 +2376,6 @@ 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) { @@ -4226,13 +4228,6 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) EditMarkAll(hwndEdit, 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_USERACCESSIBLE | SCVS_NOWRAPLINESTART) : SCVS_NONE),0); - break; - case IDM_VIEW_MARKOCCURRENCES_OFF: iMarkOccurrences = 0; // clear all marks @@ -5808,8 +5803,6 @@ void LoadSettings() bAccelWordNavigation = IniSectionGetBool(pIniSection, L"AccelWordNavigation", FALSE); - bVirtualSpaceInRectSelection = IniSectionGetBool(pIniSection,L"VirtualSpaceInRectSelection",FALSE); - bShowIndentGuides = IniSectionGetBool(pIniSection,L"ShowIndentGuides",FALSE); bTabsAsSpaces = IniSectionGetBool(pIniSection,L"TabsAsSpaces",TRUE); @@ -5985,6 +5978,7 @@ void LoadSettings() iMarkOccurrencesMaxCount = IniSectionGetInt(pIniSection,L"MarkOccurrencesMaxCount",2000); iMarkOccurrencesMaxCount = max(min(iMarkOccurrencesMaxCount,100000),2); + bOldStyleRectSelection = IniSectionGetBool(pIniSection, L"OldStyleRectSelection", FALSE); bUseOldStyleBraceMatching = IniSectionGetBool(pIniSection, L"UseOldStyleBraceMatching", FALSE); LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection); @@ -6124,7 +6118,6 @@ 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); @@ -7126,10 +7119,11 @@ void InvalidateSelections() // int BeginSelUndoAction() { + bInUndoRedoAction = TRUE; int token = -1; - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 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); @@ -7137,10 +7131,8 @@ int BeginSelUndoAction() 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); - if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { - sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); - sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); - } + sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); + sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); } else { @@ -7165,7 +7157,8 @@ int BeginSelUndoAction() void EndSelUndoAction(int token) { if (token >= 0) { - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); if (UndoRedoSelectionMap(token,&sel) >= 0) { // mode and type should not have changed if (sel.selMode == SC_SEL_LINES) { @@ -7175,10 +7168,8 @@ void EndSelUndoAction(int token) 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); - if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { - sel.anchorVS_redo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); - sel.currVS_redo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); - } + sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); + sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); } else { sel.anchorPos_redo = (int)SendMessage(hwndEdit,SCI_GETANCHOR,0,0); @@ -7187,6 +7178,7 @@ void EndSelUndoAction(int token) } UndoRedoSelectionMap(token,&sel); // set with redo action filled SendMessage(hwndEdit, SCI_ENDUNDOACTION, 0, 0); + bInUndoRedoAction = FALSE; } } @@ -7198,14 +7190,14 @@ void EndSelUndoAction(int token) // void RestoreSelectionAction(int token, DoAction doAct) { - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }; + bInUndoRedoAction = TRUE; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; if (UndoRedoSelectionMap(token,&sel) >= 0) { + PostMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 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); - 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); @@ -7213,19 +7205,17 @@ void RestoreSelectionAction(int token, DoAction doAct) else if (sel.selMode == SC_SEL_RECTANGLE) { PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)anchorPos, 0); PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)currPos, 0); - if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { - int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo); - int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo); - PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0); - PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0); - } + int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo); + int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo); + PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0); + PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0); } else { PostMessage(hwndEdit,SCI_SETSELECTION,(WPARAM)currPos,(LPARAM)anchorPos); } - PostMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0); - PostMessage(hwndEdit,SCI_CANCEL,0,0); + PostMessage(hwndEdit, SCI_CANCEL, 0, 0); } + bInUndoRedoAction = FALSE; } diff --git a/src/Notepad3.h b/src/Notepad3.h index 08929339d..130a95571 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -48,7 +48,6 @@ typedef struct _undoSel int currPos_undo; int anchorPos_redo; int currPos_redo; - int rectSelVS; int anchorVS_undo; int currVS_undo; int anchorVS_redo; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 197c62e5c364cd5582f3916e6ad3d9f1ef58873d..1584eae48d026dab198550dba2de5a152a45484f 100644 GIT binary patch delta 186 zcmV;r07d_nkPGOO3$Th^0Z5Y%O&^mE%@C8iU0wk}lMhWFlYpfVvq)a5Ad?_vJd@BX z1hdG0s3Ma>p)iwxrE0TqqL2cUaHKkuz{Mz&P^B=FP%a9S0;PVFP%a3wBBn?QlgzFr zlb~H1lOD}llN_-ovyiX$9Fx8_29x~DJd;q(Sd(B_4wID3e3QU743jFR4w9}Elkl`Y olNQdvlN>AvlOWM3ldz>av!>4K0g}){lfcC&gJ96NV9)`!_vijo=l}o! delta 232 zcmaDcnS0sxP{dHe zP|A?Vki($B5X?{jWF<4C0@;p08pJA|{IOPavO|%Od>Df#Ll8p)|tT-$a4kK zAQ4vvpUI9YiIXP?v28Z0U!gRaXR*QLHEA4^1>&V9zgR3b`NC|2%{+^LFixJgv|%#W zqO8sDmNsxsR@i7TInP>Tv(JVbGLsV`_$Hq@TQhmV`i#kaXALIrGvnJFa!!G9vVw=) bW}ORj7$^UWWSe}!Rj9e@()OxLjCtPy%G*>} diff --git a/src/resource.h b/src/resource.h index 26c243f63..b8f6cc227 100644 --- a/src/resource.h +++ b/src/resource.h @@ -382,8 +382,7 @@ #define IDM_VIEW_MARKOCCURRENCES_WORD 40452 #define IDM_VIEW_AUTOCOMPLETEWORDS 40453 #define IDM_VIEW_ACCELWORDNAV 40454 -#define IDM_VIEW_VIRTSPACERECTSEL 40455 -#define IDM_VIEW_NOPRESERVECARET 40456 +#define IDM_VIEW_NOPRESERVECARET 40455 #define IDM_HELP_ABOUT 40500 #define IDM_HELP_CMD 40501 #define IDM_TRAY_RESTORE 40600 From bc564b622a3cbfbf1e79351417d2058f53b4cc48 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 20 Oct 2017 16:18:16 +0200 Subject: [PATCH 7/7] + first prottotype of VirtualSpace RectangularSelection by default (very old behavior can be turned on by [Settings2] DenyVirtualSpaceAccess=1) --- src/Edit.c | 3 ++- src/Helpers.h | 2 ++ src/Notepad3.c | 50 +++++++++++++++++++++--------------------------- src/Notepad3.h | 1 + src/Notepad3.rc | Bin 182760 -> 182144 bytes 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 30f764889..6440db3e7 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -77,6 +77,7 @@ extern BOOL bLoadASCIIasUTF8; extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; +extern BOOL bDenyVirtualSpaceAccess; extern int iMarkOccurrences; extern int iMarkOccurrencesCount; @@ -160,7 +161,7 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_SETADDITIONALCARETSBLINK,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALCARETSVISIBLE,FALSE,0); SendMessage(hwnd,SCI_SETMOUSEWHEELCAPTURES,FALSE,0); - SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS,SCVS_NONE,0); + SendMessage(hwnd, SCI_SETVIRTUALSPACEOPTIONS, (bDenyVirtualSpaceAccess ? SCVS_NONE : SCVS_NP3_SPACE_OPT), 0); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_NEXT + (SCMOD_CTRL << 16)),SCI_PARADOWN); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_PRIOR + (SCMOD_CTRL << 16)),SCI_PARAUP); diff --git a/src/Helpers.h b/src/Helpers.h index a9c6b64cc..441aae1f3 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -97,6 +97,8 @@ __inline BOOL IniSectionSetBool(LPWSTR lpCachedIniSection, LPCWSTR lpName, BOOL #define IsWinServer() IsWindowsServer() // Indicates if the current OS is a Windows Server release. // Applications that need to distinguish between server and client versions of Windows should call this function. +#define SCVS_NP3_SPACE_OPT (SCVS_RECTANGULARSELECTION | SCVS_NOWRAPLINESTART) + enum BufferSizes { MICRO_BUFFER = 32, diff --git a/src/Notepad3.c b/src/Notepad3.c index 79b4c8e43..20b28e04e 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -67,8 +67,6 @@ HWND hDlgFindReplace = NULL; #define NUMINITIALTOOLS 24 #define MARGIN_FOLD_INDEX 2 -#define SCVS_NP3_SPACE_OPT (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE | SCVS_NOWRAPLINESTART) - TBBUTTON tbbMainWnd[] = { {0,IDT_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {1,IDT_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {2,IDT_FILE_BROWSE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, @@ -157,7 +155,7 @@ BOOL bMarkOccurrencesMatchWords; BOOL bUseOldStyleBraceMatching; BOOL bAutoCompleteWords; BOOL bAccelWordNavigation; -BOOL bOldStyleRectSelection; +BOOL bDenyVirtualSpaceAccess; BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; @@ -309,7 +307,6 @@ WCHAR g_wchWorkingDirectory[MAX_PATH+2] = { L'\0' }; // undo / redo selections -static BOOL bInUndoRedoAction = FALSE; static UT_icd UndoRedoSelection_icd = { sizeof(UndoRedoSelection_t), NULL, NULL, NULL }; static UT_array* UndoRedoSelectionUTArray = NULL; @@ -1149,20 +1146,14 @@ WININFO GetMyWindowPlacement(HWND hwnd,MONITORINFO* hMonitorInfo) // LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) { - if (!bOldStyleRectSelection && !bInUndoRedoAction) + if (!bDenyVirtualSpaceAccess) { - BOOL bIsVSpaceAccessActive = (SendMessage(hwndEdit, SCI_GETVIRTUALSPACEOPTIONS, 0, 0) != SCVS_NONE); - if (GetAsyncKeyState(VK_MENU) & SHRT_MIN) // ALT DOWN - { - if (!bIsVSpaceAccessActive) { - //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); - SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); - } + if (GetAsyncKeyState(VK_MENU) & SHRT_MIN) { // ALT-KEY DOWN + //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, (SCVS_NP3_SPACE_OPT | SCVS_USERACCESSIBLE), 0); } else { - if (bIsVSpaceAccessActive) { - SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NONE, 0); - } + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); } } @@ -5978,7 +5969,7 @@ void LoadSettings() iMarkOccurrencesMaxCount = IniSectionGetInt(pIniSection,L"MarkOccurrencesMaxCount",2000); iMarkOccurrencesMaxCount = max(min(iMarkOccurrencesMaxCount,100000),2); - bOldStyleRectSelection = IniSectionGetBool(pIniSection, L"OldStyleRectSelection", FALSE); + bDenyVirtualSpaceAccess = IniSectionGetBool(pIniSection, L"DenyVirtualSpaceAccess", FALSE); bUseOldStyleBraceMatching = IniSectionGetBool(pIniSection, L"UseOldStyleBraceMatching", FALSE); LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection); @@ -7119,11 +7110,10 @@ void InvalidateSelections() // int BeginSelUndoAction() { - bInUndoRedoAction = TRUE; int token = -1; - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; - SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 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); @@ -7131,8 +7121,10 @@ int BeginSelUndoAction() 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); + if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); + } } else { @@ -7157,8 +7149,7 @@ int BeginSelUndoAction() void EndSelUndoAction(int token) { if (token >= 0) { - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; - SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }; if (UndoRedoSelectionMap(token,&sel) >= 0) { // mode and type should not have changed if (sel.selMode == SC_SEL_LINES) { @@ -7168,8 +7159,10 @@ void EndSelUndoAction(int token) 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); - sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); - sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); + if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { + sel.anchorVS_redo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); + sel.currVS_redo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); + } } else { sel.anchorPos_redo = (int)SendMessage(hwndEdit,SCI_GETANCHOR,0,0); @@ -7178,7 +7171,6 @@ void EndSelUndoAction(int token) } UndoRedoSelectionMap(token,&sel); // set with redo action filled SendMessage(hwndEdit, SCI_ENDUNDOACTION, 0, 0); - bInUndoRedoAction = FALSE; } } @@ -7190,14 +7182,14 @@ void EndSelUndoAction(int token) // void RestoreSelectionAction(int token, DoAction doAct) { - bInUndoRedoAction = TRUE; - UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0 }; + UndoRedoSelection_t sel = { -1, -1, -1, -1, -1, 0, 0, 0, 0, 0 }; if (UndoRedoSelectionMap(token,&sel) >= 0) { - PostMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 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); + 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); @@ -7205,17 +7197,19 @@ void RestoreSelectionAction(int token, DoAction doAct) else if (sel.selMode == SC_SEL_RECTANGLE) { PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)anchorPos, 0); PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)currPos, 0); + if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo); int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo); PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0); PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0); + } } else { PostMessage(hwndEdit,SCI_SETSELECTION,(WPARAM)currPos,(LPARAM)anchorPos); } + PostMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0); PostMessage(hwndEdit, SCI_CANCEL, 0, 0); } - bInUndoRedoAction = FALSE; } diff --git a/src/Notepad3.h b/src/Notepad3.h index 130a95571..08929339d 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; int anchorVS_undo; int currVS_undo; int anchorVS_redo; diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 1584eae48d026dab198550dba2de5a152a45484f..614681af0d92fca965542af1c673086ed10a6a58 100644 GIT binary patch delta 137 zcmV;40CxZAlM8^43$Th^ljc$mlYWW_lb~IA0Yj5qZX6Un=rEsqxb=no~3}33ZiPW?xlbUlOVA$lWsc{vrMqq9Ft&J4wKBye3PKB rXp@f3Fq6JE4zpCwAOVvgNFK8+(3}C2{#gc-&_xo1deXOg(gAMwk|sW< delta 179 zcmZqZ=YBDndqY<&qsQdJF44&gVk;OO!K?>Mq&9oRO>&;RW`V)vS4*-s-�#9(rO9@pfYC3QfWV{^|^56;PQYYir^iWQjLaVBc=oAm~h^Q=WC_wC}E z9CKV{a>E=spqSd^4QfEX2H)mI>-}UVC!BTyn|9#zuE__?cs47XRbZUF;Vf8iv%tAm ZjFYY!OujH%2&Aa_)cNhF&NFWN4gjz@Q@H>D