diff --git a/Build/Notepad3.ini b/Build/Notepad3.ini index fedef105e..67252911a 100644 --- a/Build/Notepad3.ini +++ b/Build/Notepad3.ini @@ -31,6 +31,7 @@ SettingsVersion=5 ;FindReplaceOpacityLevel=50 ;RelativeFileMRU=1 ;ReuseWindow=0 +;SaveBlankNewFile=true ;SciFontQuality=3 ;SimpleIndentGuides=0 ;SingleFileInstance=1 diff --git a/lexilla/lexers/LexInno.cxx b/lexilla/lexers/LexInno.cxx index c478d2576..ffa1aa694 100644 --- a/lexilla/lexers/LexInno.cxx +++ b/lexilla/lexers/LexInno.cxx @@ -89,6 +89,7 @@ static void ColouriseInnoDoc(Sci_PositionU startPos, Sci_Position length, int, W // using the hand-written state machine shown below styler.StartAt(startPos); styler.StartSegment(startPos); + for (Sci_Position i = startPos; i < lengthDoc; i++) { chPrev = ch; ch = chNext; diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index e257e326f..c44441b2a 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1216,6 +1216,8 @@ void LoadSettings() Flags.NoHTMLGuess = IniSectionGetBool(IniSecSettings2, L"NoHTMLGuess", DefaultFlags.NoHTMLGuess); Flags.NoCGIGuess = IniSectionGetBool(IniSecSettings2, L"NoCGIGuess", DefaultFlags.NoCGIGuess); Flags.NoFileVariables = IniSectionGetBool(IniSecSettings2, L"NoFileVariables", DefaultFlags.NoFileVariables); + + Flags.SaveBlankNewFile = IniSectionGetBool(IniSecSettings2, L"SaveBlankNewFile", DefaultFlags.SaveBlankNewFile); Flags.PrintFileAndLeave = Globals.CmdLnFlag_PrintFileAndLeave; diff --git a/src/Notepad3.c b/src/Notepad3.c index 701ba73ee..28ed234ce 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -779,6 +779,7 @@ static void _InitGlobals() Flags.NoHTMLGuess =DefaultFlags.NoHTMLGuess = false; Flags.NoCGIGuess = DefaultFlags.NoCGIGuess = false; Flags.NoFileVariables = DefaultFlags.NoFileVariables = false; + Flags.SaveBlankNewFile = DefaultFlags.SaveBlankNewFile = true; Flags.ShellUseSystemMRU = DefaultFlags.ShellUseSystemMRU = true; Flags.PrintFileAndLeave = DefaultFlags.PrintFileAndLeave = 0; Flags.bPreserveFileModTime = DefaultFlags.bPreserveFileModTime = false; @@ -11787,24 +11788,24 @@ bool FileSave(FileSaveFlags fSaveFlags) fioStatus.iEncoding = Encoding_GetCurrent(); fioStatus.iEOLMode = SciCall_GetEOLMode(); -#if 0 bool bIsEmptyNewFile = false; - if (Path_IsEmpty(Paths.CurrentFile)) { - DocPos const cchText = SciCall_GetTextLength(); - if (cchText <= 0) { - bIsEmptyNewFile = true; - } else if (cchText < 2048) { - char chTextBuf[2048] = { '\0' }; - SciCall_GetText(COUNTOF(chTextBuf) - 1, chTextBuf); - StrTrimA(chTextBuf, " \t\n\r"); - if (StrIsEmptyA(chTextBuf)) { + if (Flags.SaveBlankNewFile) { + bIsEmptyNewFile = (Path_IsEmpty(Paths.CurrentFile) && (SciCall_GetTextLength() <= 0LL)); + } + else { + if (Path_IsEmpty(Paths.CurrentFile)) { + DocPos const cchText = SciCall_GetTextLength(); + if (cchText <= 0) { bIsEmptyNewFile = true; } + else { + struct Sci_TextToFindFull ft = { { 0, 0 }, "\\S+", { 0, 0 } }; + ft.chrg.cpMax = Sci_GetDocEndPosition(); + DocPos const iPos = SciCall_FindTextFull(SCFIND_REGEXP, &ft); + bIsEmptyNewFile = ((iPos < 0) || (iPos >= ft.chrg.cpMax)); + } } } -#else - bool const bIsEmptyNewFile = (Path_IsEmpty(Paths.CurrentFile) && (SciCall_GetTextLength() <= 0LL)); -#endif bool const bSaveNeeded = (IsSaveNeeded() || IsFileChangedFlagSet()) && !bIsEmptyNewFile; diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 11c446ce6..553dcf87b 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -722,6 +722,7 @@ typedef struct FLAGS_T { bool RelativeFileMRU; bool PortableMyDocs; bool NoFadeHidden; + bool SaveBlankNewFile; bool SimpleIndentGuides; bool NoHTMLGuess; bool NoCGIGuess;