diff --git a/lexilla/Lexilla.vcxproj.filters b/lexilla/Lexilla.vcxproj.filters index 1c5a1f015..d6b568044 100644 --- a/lexilla/Lexilla.vcxproj.filters +++ b/lexilla/Lexilla.vcxproj.filters @@ -260,9 +260,6 @@ lexers - - lexers_x - lexlib @@ -275,6 +272,9 @@ lexers + + lexers_x + diff --git a/lexilla/lexers_x/CharSetX.h b/lexilla/lexers_x/CharSetX.h index c01c2ffd4..3473ec213 100644 --- a/lexilla/lexers_x/CharSetX.h +++ b/lexilla/lexers_x/CharSetX.h @@ -68,9 +68,9 @@ constexpr bool IsALetter(const int ch) noexcept return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); } -constexpr bool IsLineBreak(const int ch) noexcept -{ - return ((ch == '\n') || (ch == '\r') || (ch == '\0')); +constexpr bool IsNewline(const int ch) { + // sc.GetRelative(i) returns '\0' if out of range + return (ch == '\n' || ch == '\r' || ch == '\0'); } constexpr bool IsLineEndUTF8(const unsigned char ch0, diff --git a/lexilla/lexers_x/LexCSV.cxx b/lexilla/lexers_x/LexCSV.cxx index b72683837..02da57b5f 100644 --- a/lexilla/lexers_x/LexCSV.cxx +++ b/lexilla/lexers_x/LexCSV.cxx @@ -230,7 +230,7 @@ constexpr Sci_PositionU CountCharOccTillLineEnd(StyleContext& sc, const Sci_Posi { Sci_Position i = 0; Sci_PositionU count = 0; - while (((sc.currentPos + i) < endPos) && !IsLineBreak(sc.GetRelative(i))) + while (((sc.currentPos + i) < endPos) && !IsNewline(sc.GetRelative(i))) { if (sc.GetRelative(++i) == sc.ch) { ++count; }; } diff --git a/lexilla/lexers_x/LexJSON.cxx b/lexilla/lexers_x/LexJSON.cxx index 15285c6f1..e72528217 100644 --- a/lexilla/lexers_x/LexJSON.cxx +++ b/lexilla/lexers_x/LexJSON.cxx @@ -361,7 +361,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, } break; case SCE_JSON_LINECOMMENT: - if (context.atLineEnd) { + if (context.MatchLineEnd()) { context.SetState(SCE_JSON_DEFAULT); } break; @@ -393,10 +393,10 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, } } break; - case SCE_JSON_PROPERTYNAME: - [[fallthrough]]; - case SCE_JSON_STRING: - if (context.ch == ':' && !(doubleQuotCntx || singleQuotCntx)) { + case SCE_JSON_PROPERTYNAME: + [[fallthrough]]; + case SCE_JSON_STRING: + if (context.ch == ':' && !(doubleQuotCntx || singleQuotCntx)) { context.SetState(SCE_JSON_OPERATOR); } else if (context.ch == '"' && doubleQuotCntx) { if (compactIRI.shouldHighlight()) { @@ -419,7 +419,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, } singleQuotCntx = false; } else if (context.ch == '\\') { - // line continuation (yet: LF and CRLF only) ? + // line continuation (yet: LF and CRLF only) ? if (context.Match("\\\n")) { context.Forward(); context.ForwardSetState(context.state); @@ -489,7 +489,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, context.SetState(SCE_JSON_DEFAULT); break; case SCE_JSON_ERROR: - if (context.atLineEnd) { + if (context.MatchLineEnd()) { context.SetState(SCE_JSON_DEFAULT); } break; diff --git a/lexilla/lexers_x/LexKotlin.cxx b/lexilla/lexers_x/LexKotlin.cxx index 9445173bc..f97d8f2c6 100644 --- a/lexilla/lexers_x/LexKotlin.cxx +++ b/lexilla/lexers_x/LexKotlin.cxx @@ -271,7 +271,7 @@ struct EscapeSequence { // highlight any character as escape sequence. bool resetEscapeState(int state, int chNext) noexcept { - if (IsLineBreak(chNext)) { + if (IsNewline(chNext)) { return false; } outerState = state; diff --git a/lexilla/lexers_x/LexMarkdown.cxx b/lexilla/lexers_x/LexMarkdown.cxx index 3f99c6743..62c70a701 100644 --- a/lexilla/lexers_x/LexMarkdown.cxx +++ b/lexilla/lexers_x/LexMarkdown.cxx @@ -58,6 +58,7 @@ using namespace Lexilla; // True if can follow ch down to the end with possibly trailing whitespace +// Does not set the state SCE_MARKDOWN_LINE_BEGIN as to allow further processing static bool FollowToLineEnd(const int ch, const int state, const Sci_PositionU endPos, StyleContext &sc) { Sci_Position i = 0; while (sc.GetRelative(++i) == ch) @@ -65,7 +66,7 @@ static bool FollowToLineEnd(const int ch, const int state, const Sci_PositionU e // Skip over whitespace while (IsASpaceOrTab(sc.GetRelative(i)) && sc.currentPos + i < endPos) ++i; - if (IsLineBreak(sc.GetRelative(i)) || sc.currentPos + i == endPos) { + if (IsNewline(sc.GetRelative(i)) || sc.currentPos + i == endPos) { sc.Forward(i); sc.ChangeState(state); sc.SetState(SCE_MARKDOWN_LINE_BEGIN); @@ -74,32 +75,8 @@ static bool FollowToLineEnd(const int ch, const int state, const Sci_PositionU e else return false; } -#if 0 - // Set the state on text section from current to length characters, // then set the rest until the newline to default, except for any characters matching token -static void SetStateAndZoom(const int state, const Sci_Position length, const int token, StyleContext &sc) { - sc.SetState(state); - sc.Forward(length); - sc.SetState(SCE_MARKDOWN_DEFAULT); - sc.Forward(); - bool started = false; - while (sc.More() && !IsNewline(sc.ch)) { - if (sc.ch == token && !started) { - sc.SetState(state); - started = true; - } - else if (sc.ch != token) { - sc.SetState(SCE_MARKDOWN_DEFAULT); - started = false; - } - sc.Forward(); - } - sc.SetState(SCE_MARKDOWN_LINE_BEGIN); -} - -#else - static void SetStateAndZoom(const int state, const Sci_Position length, const int token, StyleContext& sc) { sc.SetState(state); sc.Forward(length); @@ -117,13 +94,11 @@ static void SetStateAndZoom(const int state, const Sci_Position length, const in sc.SetState(SCE_MARKDOWN_LINE_BEGIN); } -#endif - // Does the previous line have more than spaces and tabs? static bool HasPrevLineContent(StyleContext &sc) { Sci_Position i = 0; // Go back to the previous newline - while ((--i + (Sci_Position)sc.currentPos) >= 0 && !IsLineBreak(sc.GetRelative(i))) + while ((--i + (Sci_Position)sc.currentPos) >= 0 && !IsNewline(sc.GetRelative(i))) ; while ((--i + (Sci_Position)sc.currentPos) >= 0) { const int ch = sc.GetRelative(i); @@ -143,7 +118,7 @@ static bool IsCompleteStyleRegion(StyleContext &sc, const char *token) { bool found = false; const size_t start = strlen(token); Sci_Position i = static_cast(start); - while (!IsLineBreak(sc.GetRelative(i))) { + while (!IsNewline(sc.GetRelative(i))) { // make sure an empty pair of single-char tokens doesn't match // with a longer token: {*}{*} != {**} if (sc.GetRelative(i) == *token && sc.GetRelative(i - 1) != *token) { @@ -166,7 +141,7 @@ static bool IsValidHrule(const Sci_PositionU endPos, StyleContext &sc) { // hit a terminating character else if (!IsASpaceOrTab(ch) || (sc.currentPos + i) == endPos) { // Are we a valid HRULE - if ((IsLineBreak(ch) || (sc.currentPos + i) == endPos) && + if ((IsNewline(ch) || (sc.currentPos + i) == endPos) && count >= 3 && !HasPrevLineContent(sc)) { sc.SetState(SCE_MARKDOWN_HRULE); sc.Forward(i); @@ -256,37 +231,37 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int */ // Strong else if (sc.state == SCE_MARKDOWN_STRONG1) { - if ((sc.Match("**") && sc.chPrev != ' ') || IsLineBreak(sc.GetRelative(2))) { + if ((sc.Match("**") && sc.chPrev != ' ') || IsNewline(sc.GetRelative(2))) { sc.Forward(2); sc.SetState(SCE_MARKDOWN_DEFAULT); } } else if (sc.state == SCE_MARKDOWN_STRONG2) { - if ((sc.Match("__") && sc.chPrev != ' ') || IsLineBreak(sc.GetRelative(2))) { + if ((sc.Match("__") && sc.chPrev != ' ') || IsNewline(sc.GetRelative(2))) { sc.Forward(2); sc.SetState(SCE_MARKDOWN_DEFAULT); } } // Emphasis else if (sc.state == SCE_MARKDOWN_EM1) { - if ((sc.ch == '*' && sc.chPrev != ' ') || IsLineBreak(sc.chNext)) + if ((sc.ch == '*' && sc.chPrev != ' ') || IsNewline(sc.chNext)) sc.ForwardSetState(SCE_MARKDOWN_DEFAULT); } else if (sc.state == SCE_MARKDOWN_EM2) { - if ((sc.ch == '_' && sc.chPrev != ' ') || IsLineBreak(sc.chNext)) + if ((sc.ch == '_' && sc.chPrev != ' ') || IsNewline(sc.chNext)) sc.ForwardSetState(SCE_MARKDOWN_DEFAULT); } else if (sc.state == SCE_MARKDOWN_CODEBK) { if (sc.atLineStart && sc.Match("~~~")) { Sci_Position i = 1; - while (!IsLineBreak(sc.GetRelative(i)) && sc.currentPos + i < endPos) + while (!IsNewline(sc.GetRelative(i)) && sc.currentPos + i < endPos) i++; sc.Forward(i); sc.SetState(SCE_MARKDOWN_DEFAULT); } } else if (sc.state == SCE_MARKDOWN_STRIKEOUT) { - if ((sc.Match("~~") && sc.chPrev != ' ') || IsLineBreak(sc.GetRelative(2))) { + if ((sc.Match("~~") && sc.chPrev != ' ') || IsNewline(sc.GetRelative(2))) { sc.Forward(2); sc.SetState(SCE_MARKDOWN_DEFAULT); } @@ -462,7 +437,8 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int // Emphasis else if (sc.ch == '*' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "*")) { sc.SetState(SCE_MARKDOWN_EM1); - } else if (sc.ch == '_' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "_")) { + } + else if (sc.ch == '_' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "_")) { sc.SetState(SCE_MARKDOWN_EM2); } // Strikeout @@ -472,7 +448,7 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int sc.Forward(); } // Beginning of line - else if (IsLineBreak(sc.ch)) { + else if (IsNewline(sc.ch)) { sc.SetState(SCE_MARKDOWN_LINE_BEGIN); } } diff --git a/lexilla/lexers_x/LexTOML.cxx b/lexilla/lexers_x/LexTOML.cxx index 6b252b7f0..83b258a61 100644 --- a/lexilla/lexers_x/LexTOML.cxx +++ b/lexilla/lexers_x/LexTOML.cxx @@ -470,7 +470,7 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int // ------------------------------------------------------------------------ - if (IsLineBreak(sc.ch)) + if (IsNewline(sc.ch)) { continue; // eat } diff --git a/lexilla/lexers_x/orig/LexJSON.cxx b/lexilla/lexers_x/orig/LexJSON.cxx index 92616715a..6ba428110 100644 --- a/lexilla/lexers_x/orig/LexJSON.cxx +++ b/lexilla/lexers_x/orig/LexJSON.cxx @@ -292,7 +292,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, } break; case SCE_JSON_LINECOMMENT: - if (context.atLineEnd) { + if (context.MatchLineEnd()) { context.SetState(SCE_JSON_DEFAULT); } break; @@ -311,7 +311,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, } if (context.ch == '"') { context.SetState(stringStyleBefore); - context.ForwardSetState(SCE_C_DEFAULT); + context.ForwardSetState(SCE_JSON_DEFAULT); } else if (context.ch == '\\') { if (!escapeSeq.newSequence(context.chNext)) { context.SetState(SCE_JSON_ERROR); @@ -383,7 +383,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, context.SetState(SCE_JSON_DEFAULT); break; case SCE_JSON_ERROR: - if (context.atLineEnd) { + if (context.MatchLineEnd()) { context.SetState(SCE_JSON_DEFAULT); } break; diff --git a/lexilla/lexers_x/orig/LexMarkdown.cxx b/lexilla/lexers_x/orig/LexMarkdown.cxx index 36346398b..837cb89bf 100644 --- a/lexilla/lexers_x/orig/LexMarkdown.cxx +++ b/lexilla/lexers_x/orig/LexMarkdown.cxx @@ -66,6 +66,7 @@ constexpr bool IsNewline(const int ch) { } // True if can follow ch down to the end with possibly trailing whitespace +// Does not set the state SCE_MARKDOWN_LINE_BEGIN as to allow further processing static bool FollowToLineEnd(const int ch, const int state, const Sci_PositionU endPos, StyleContext &sc) { Sci_Position i = 0; while (sc.GetRelative(++i) == ch) @@ -74,9 +75,8 @@ static bool FollowToLineEnd(const int ch, const int state, const Sci_PositionU e while (IsASpaceOrTab(sc.GetRelative(i)) && sc.currentPos + i < endPos) ++i; if (IsNewline(sc.GetRelative(i)) || sc.currentPos + i == endPos) { + sc.SetState(state); sc.Forward(i); - sc.ChangeState(state); - sc.SetState(SCE_MARKDOWN_LINE_BEGIN); return true; } else return false; @@ -126,15 +126,15 @@ static bool AtTermStart(StyleContext &sc) { static bool IsCompleteStyleRegion(StyleContext &sc, const char *token) { bool found = false; - const size_t start = strlen(token); + const size_t start = strlen(token); Sci_Position i = static_cast(start); while (!IsNewline(sc.GetRelative(i))) { // make sure an empty pair of single-char tokens doesn't match // with a longer token: {*}{*} != {**} - if (sc.GetRelative(i) == *token && sc.GetRelative(i - 1) != *token) { - found = start > 1U ? sc.GetRelative(i + 1) == token[1] : true; - break; - } + if (sc.GetRelative(i) == *token && sc.GetRelative(i - 1) != *token) { + found = start > 1U ? sc.GetRelative(i + 1) == token[1] : true; + break; + } i++; } return AtTermStart(sc) && found; @@ -160,14 +160,14 @@ static bool IsValidHrule(const Sci_PositionU endPos, StyleContext &sc) { } else { sc.SetState(SCE_MARKDOWN_DEFAULT); - return false; + return false; } } } } static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, - WordList **, Accessor &styler) { + WordList **, Accessor &styler) { Sci_PositionU endPos = startPos + length; int precharCount = 0; bool isLinkNameDetecting = false; @@ -176,6 +176,10 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int // in the default state. bool freezeCursor = false; + // property lexer.markdown.header.eolfill + // Set to 1 to highlight all ATX header text. + bool headerEOLFill = styler.GetPropertyInt("lexer.markdown.header.eolfill", 0) == 1; + StyleContext sc(startPos, static_cast(length), initStyle, styler); while (sc.More()) { @@ -265,22 +269,45 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int } else if (sc.state == SCE_MARKDOWN_LINE_BEGIN) { // Header - if (sc.Match("######")) - SetStateAndZoom(SCE_MARKDOWN_HEADER6, 6, '#', sc); - else if (sc.Match("#####")) - SetStateAndZoom(SCE_MARKDOWN_HEADER5, 5, '#', sc); - else if (sc.Match("####")) - SetStateAndZoom(SCE_MARKDOWN_HEADER4, 4, '#', sc); - else if (sc.Match("###")) - SetStateAndZoom(SCE_MARKDOWN_HEADER3, 3, '#', sc); - else if (sc.Match("##")) - SetStateAndZoom(SCE_MARKDOWN_HEADER2, 2, '#', sc); + if (sc.Match("######")) { + if (headerEOLFill) + sc.SetState(SCE_MARKDOWN_HEADER6); + else + SetStateAndZoom(SCE_MARKDOWN_HEADER6, 6, '#', sc); + } + else if (sc.Match("#####")) { + if (headerEOLFill) + sc.SetState(SCE_MARKDOWN_HEADER5); + else + SetStateAndZoom(SCE_MARKDOWN_HEADER5, 5, '#', sc); + } + else if (sc.Match("####")) { + if (headerEOLFill) + sc.SetState(SCE_MARKDOWN_HEADER4); + else + SetStateAndZoom(SCE_MARKDOWN_HEADER4, 4, '#', sc); + } + else if (sc.Match("###")) { + if (headerEOLFill) + sc.SetState(SCE_MARKDOWN_HEADER3); + else + SetStateAndZoom(SCE_MARKDOWN_HEADER3, 3, '#', sc); + } + else if (sc.Match("##")) { + if (headerEOLFill) + sc.SetState(SCE_MARKDOWN_HEADER2); + else + SetStateAndZoom(SCE_MARKDOWN_HEADER2, 2, '#', sc); + } else if (sc.Match("#")) { // Catch the special case of an unordered list if (sc.chNext == '.' && IsASpaceOrTab(sc.GetRelative(2))) { precharCount = 0; sc.SetState(SCE_MARKDOWN_PRECHAR); } + else if (headerEOLFill) { + sc.SetState(SCE_MARKDOWN_HEADER1); + } else SetStateAndZoom(SCE_MARKDOWN_HEADER1, 1, '#', sc); } @@ -292,14 +319,18 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int sc.SetState(SCE_MARKDOWN_DEFAULT); } else if (sc.ch == '=') { - if (HasPrevLineContent(sc) && FollowToLineEnd('=', SCE_MARKDOWN_HEADER1, endPos, sc)) - ; + if (HasPrevLineContent(sc) && FollowToLineEnd('=', SCE_MARKDOWN_HEADER1, endPos, sc)) { + if (!headerEOLFill) + sc.SetState(SCE_MARKDOWN_LINE_BEGIN); + } else sc.SetState(SCE_MARKDOWN_DEFAULT); } else if (sc.ch == '-') { - if (HasPrevLineContent(sc) && FollowToLineEnd('-', SCE_MARKDOWN_HEADER2, endPos, sc)) - ; + if (HasPrevLineContent(sc) && FollowToLineEnd('-', SCE_MARKDOWN_HEADER2, endPos, sc)) { + if (!headerEOLFill) + sc.SetState(SCE_MARKDOWN_LINE_BEGIN); + } else { precharCount = 0; sc.SetState(SCE_MARKDOWN_PRECHAR); @@ -315,9 +346,15 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int // The header lasts until the newline else if (sc.state == SCE_MARKDOWN_HEADER1 || sc.state == SCE_MARKDOWN_HEADER2 || - sc.state == SCE_MARKDOWN_HEADER3 || sc.state == SCE_MARKDOWN_HEADER4 || - sc.state == SCE_MARKDOWN_HEADER5 || sc.state == SCE_MARKDOWN_HEADER6) { - if (IsNewline(sc.ch)) + sc.state == SCE_MARKDOWN_HEADER3 || sc.state == SCE_MARKDOWN_HEADER4 || + sc.state == SCE_MARKDOWN_HEADER5 || sc.state == SCE_MARKDOWN_HEADER6) { + if (headerEOLFill) { + if (sc.atLineStart) { + sc.SetState(SCE_MARKDOWN_LINE_BEGIN); + freezeCursor = true; + } + } + else if (IsNewline(sc.ch)) sc.SetState(SCE_MARKDOWN_LINE_BEGIN); } @@ -367,21 +404,21 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int // Any link if (sc.state == SCE_MARKDOWN_LINK) { if (sc.Match("](") && sc.GetRelative(-1) != '\\') { - sc.Forward(2); - isLinkNameDetecting = true; + sc.Forward(2); + isLinkNameDetecting = true; } else if (sc.Match("]:") && sc.GetRelative(-1) != '\\') { - sc.Forward(2); - sc.SetState(SCE_MARKDOWN_DEFAULT); + sc.Forward(2); + sc.SetState(SCE_MARKDOWN_DEFAULT); } else if (!isLinkNameDetecting && sc.ch == ']' && sc.GetRelative(-1) != '\\') { - sc.Forward(); - sc.SetState(SCE_MARKDOWN_DEFAULT); + sc.Forward(); + sc.SetState(SCE_MARKDOWN_DEFAULT); } else if (isLinkNameDetecting && sc.ch == ')' && sc.GetRelative(-1) != '\\') { - sc.Forward(); - sc.SetState(SCE_MARKDOWN_DEFAULT); - isLinkNameDetecting = false; + sc.Forward(); + sc.SetState(SCE_MARKDOWN_DEFAULT); + isLinkNameDetecting = false; } } @@ -393,11 +430,11 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int } // Links and Images if (sc.Match("![")) { - sc.SetState(SCE_MARKDOWN_LINK); - sc.Forward(1); + sc.SetState(SCE_MARKDOWN_LINK); + sc.Forward(1); } else if (sc.ch == '[' && sc.GetRelative(-1) != '\\') { - sc.SetState(SCE_MARKDOWN_LINK); + sc.SetState(SCE_MARKDOWN_LINK); } // Code - also a special case for alternate inside spacing else if (sc.Match("``") && sc.GetRelative(3) != ' ' && AtTermStart(sc)) { @@ -412,7 +449,7 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int else if (sc.Match("**") && sc.GetRelative(2) != ' ' && IsCompleteStyleRegion(sc, "**")) { sc.SetState(SCE_MARKDOWN_STRONG1); sc.Forward(); - } + } else if (sc.Match("__") && sc.GetRelative(2) != ' ' && IsCompleteStyleRegion(sc, "__")) { sc.SetState(SCE_MARKDOWN_STRONG2); sc.Forward(); @@ -420,12 +457,13 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int // Emphasis else if (sc.ch == '*' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "*")) { sc.SetState(SCE_MARKDOWN_EM1); - } else if (sc.ch == '_' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "_")) { + } + else if (sc.ch == '_' && sc.chNext != ' ' && IsCompleteStyleRegion(sc, "_")) { sc.SetState(SCE_MARKDOWN_EM2); } // Strikeout else if (sc.Match("~~") && !(sc.GetRelative(2) == '~' || sc.GetRelative(2) == ' ') && - IsCompleteStyleRegion(sc, "~~")) { + IsCompleteStyleRegion(sc, "~~")) { sc.SetState(SCE_MARKDOWN_STRIKEOUT); sc.Forward(); } diff --git a/src/Notepad3.c b/src/Notepad3.c index af5fe623b..8bbc60a29 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2310,6 +2310,7 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl) ResetMouseDWellTime(); int const iCaretPolicy = CARET_SLOP | CARET_EVEN | CARET_STRICT; + SciCall_SetXCaretPolicy(iCaretPolicy, Settings2.CurrentLineHorizontalSlop); s_iCaretPolicyV = (Settings2.CurrentLineVerticalSlop > 0) ? iCaretPolicy : CARET_EVEN; SciCall_SetXCaretPolicy(iCaretPolicy, Settings2.CurrentLineHorizontalSlop); SciCall_SetYCaretPolicy(s_iCaretPolicyV, Settings2.CurrentLineVerticalSlop); @@ -10934,6 +10935,9 @@ bool FileRevert(const HPATHL hfile_pth, bool bIgnoreCmdLnEnc) bool bPreserveView = true; DocLn const curLineNum = Sci_GetCurrentLineNumber(); + DocPos const curColumnNum = Sci_GetCurrentColumnNumber(); + DocLn const firstVisibleLine = SciCall_GetFirstVisibleLine(); + bool const bIsAtDocEnd = (curLineNum >= (Sci_GetLastDocLineNumber() - Settings2.CurrentLineVerticalSlop)); Encoding_SrcWeak(CPI_NONE); @@ -10972,9 +10976,8 @@ bool FileRevert(const HPATHL hfile_pth, bool bIgnoreCmdLnEnc) } if (bPreserveView) { - SciCall_SetYCaretPolicy(s_iCaretPolicyV | CARET_JUMPS, Settings2.CurrentLineVerticalSlop); - EditJumpTo(curLineNum + 1, 0); - SciCall_SetYCaretPolicy(s_iCaretPolicyV, Settings2.CurrentLineVerticalSlop); + SciCall_SetFirstVisibleLine(firstVisibleLine); + Sci_GotoPosChooseCaret(SciCall_FindColumn(curLineNum, curColumnNum)); } } diff --git a/src/SciCall.h b/src/SciCall.h index 305bad95b..ff2060728 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -739,6 +739,7 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool); #define Sci_HaveUndoRedoHistory() (SciCall_CanUndo() || SciCall_CanRedo()) +#define Sci_GetCurrentColumnNumber() SciCall_GetColumn(SciCall_GetCurrentPos()) #define Sci_GetCurrentLineNumber() SciCall_LineFromPosition(SciCall_GetCurrentPos()) #define Sci_GetLastDocLineNumber() (SciCall_GetLineCount() - 1)