diff --git a/src/Dialogs.c b/src/Dialogs.c index 392842409f..928e10bd67 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -1591,6 +1591,7 @@ static INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, case WM_INITDIALOG: { WCHAR wch[MAX_EDITLEXER_NAME_SIZE]; LPCWSTR pszName; + Style_LoadTabSettings(pLexCurrent); #if NP2_ENABLE_LOCALIZE_LEXER_NAME if (GetString(pLexCurrent->rid, wch, COUNTOF(wch))) { pszName = wch; @@ -1710,12 +1711,7 @@ static INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, fvCurFile.bTabIndents = IsButtonChecked(hwnd, IDC_TAB_INDENT); tabSettings.bTabIndents = fvCurFile.bTabIndents; tabSettings.bBackspaceUnindents = IsButtonChecked(hwnd, IDC_BACKSPACE_UNINDENT); - - LPCWSTR lpSection = pLexCurrent->pszName; - IniSetIntEx(lpSection, L"TabWidth", tabSettings.schemeTabWidth, pLexCurrent->defaultTabWidth); - IniSetIntEx(lpSection, L"IndentWidth", tabSettings.schemeIndentWidth, pLexCurrent->defaultIndentWidth); - IniSetBoolEx(lpSection, L"TabsAsSpaces", tabSettings.schemeTabsAsSpaces, pLexCurrent->defaultTabsAsSpaces); - IniSetBoolEx(lpSection, L"UseGlobalTabSettings", tabSettings.schemeUseGlobalTabSettings, pLexCurrent->defaultUseGlobalTabSettings); + Style_SaveTabSettings(pLexCurrent); EndDialog(hwnd, IDOK); } break; diff --git a/src/Styles.c b/src/Styles.c index d625e9ff14..501921b92b 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -610,7 +610,7 @@ static inline void FindDarkThemeFile(void) { FindExtraIniFile(darkStyleThemeFilePath, L"Notepad2 DarkTheme.ini", L"DarkTheme.ini"); } -static inline void Style_LoadTabSettings(PEDITLEXER pLex) { +void Style_LoadTabSettings(PEDITLEXER pLex) { LPCWSTR lpSection = pLex->pszName; int iValue = IniGetInt(lpSection, L"TabWidth", pLex->defaultTabWidth); tabSettings.schemeTabWidth = clamp_i(iValue, TAB_WIDTH_MIN, TAB_WIDTH_MAX); @@ -620,6 +620,21 @@ static inline void Style_LoadTabSettings(PEDITLEXER pLex) { tabSettings.schemeUseGlobalTabSettings = IniGetInt(lpSection, L"UseGlobalTabSettings", pLex->defaultUseGlobalTabSettings); } +void Style_SaveTabSettings(PEDITLEXER pLex) { + LPCWSTR lpSection = pLex->pszName; + IniSetIntEx(lpSection, L"TabWidth", tabSettings.schemeTabWidth, pLex->defaultTabWidth); + IniSetIntEx(lpSection, L"IndentWidth", tabSettings.schemeIndentWidth, pLex->defaultIndentWidth); + IniSetBoolEx(lpSection, L"TabsAsSpaces", tabSettings.schemeTabsAsSpaces, pLex->defaultTabsAsSpaces); + IniSetBoolEx(lpSection, L"UseGlobalTabSettings", tabSettings.schemeUseGlobalTabSettings, pLex->defaultUseGlobalTabSettings); +} + +static inline void SaveLexTabSettings(IniSectionOnSave *pIniSection, PEDITLEXER pLex) { + IniSectionSetIntEx(pIniSection, L"TabWidth", tabSettings.schemeTabWidth, pLex->defaultTabWidth); + IniSectionSetIntEx(pIniSection, L"IndentWidth", tabSettings.schemeIndentWidth, pLex->defaultIndentWidth); + IniSectionSetBoolEx(pIniSection, L"TabsAsSpaces", tabSettings.schemeTabsAsSpaces, pLex->defaultTabsAsSpaces); + IniSectionSetBoolEx(pIniSection, L"UseGlobalTabSettings", tabSettings.schemeUseGlobalTabSettings, pLex->defaultUseGlobalTabSettings); +} + static void Style_LoadOneEx(PEDITLEXER pLex, IniSection *pIniSection, WCHAR *pIniSectionBuf, int cchIniSection) { LPCWSTR themePath = GetStyleThemeFilePath(); GetPrivateProfileSection(pLex->pszName, pIniSectionBuf, cchIniSection, themePath); @@ -924,10 +939,7 @@ void Style_Save(void) { IniSectionSetStringEx(pIniSection, pLex->Styles[i].pszName, pLex->Styles[i].szValue, pLex->Styles[i].pszDefault); } if (pLex == pLexCurrent && pLex->iStyleTheme == StyleTheme_Default) { - IniSectionSetIntEx(pIniSection, L"TabWidth", tabSettings.schemeTabWidth, pLex->defaultTabWidth); - IniSectionSetIntEx(pIniSection, L"IndentWidth", tabSettings.schemeIndentWidth, pLex->defaultIndentWidth); - IniSectionSetBoolEx(pIniSection, L"TabsAsSpaces", tabSettings.schemeTabsAsSpaces, pLex->defaultTabsAsSpaces); - IniSectionSetBoolEx(pIniSection, L"UseGlobalTabSettings", tabSettings.schemeUseGlobalTabSettings, pLex->defaultUseGlobalTabSettings); + SaveLexTabSettings(pIniSection, pLex); } // delete this section if nothing changed WritePrivateProfileSection(pLex->pszName, StrIsEmpty(pIniSectionBuf) ? NULL : pIniSectionBuf, themePath); @@ -1511,8 +1523,11 @@ void Style_SetLexer(PEDITLEXER pLexNew, BOOL bLexerChanged) { int rid = pLexNew->rid; if (bLexerChanged) { - Style_LoadTabSettings(pLexNew); - FileVars_Apply(&fvCurFile); + if ((fvCurFile.mask & FV_MaskHasFileTabSettings) != FV_MaskHasFileTabSettings) { + // otherwise, the same tab settings already applied in EditSetNewText(). + Style_LoadTabSettings(pLexNew); + FileVars_Apply(&fvCurFile); + } SciCall_SetLexer(iLexer); if (iLexer == SCLEX_CPP || iLexer == SCLEX_MATLAB) { diff --git a/src/Styles.h b/src/Styles.h index f9d112ffb0..6740a1fb31 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -46,6 +46,8 @@ void Style_Load(void); void Style_Save(void); BOOL Style_Import(HWND hwnd); BOOL Style_Export(HWND hwnd); +void Style_LoadTabSettings(PEDITLEXER pLex); +void Style_SaveTabSettings(PEDITLEXER pLex); void Style_DetectBaseFontSize(HWND hwnd); HFONT Style_CreateCodeFont(UINT dpi);