mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ add switch ([Settings2] UseOldStyleBraceMatching) to preserve old style brace matching behavior
This commit is contained in:
parent
2c9f47950a
commit
cdecfb5756
Binary file not shown.
@ -159,6 +159,10 @@ MarkOccurrencesMaxCount
|
||||
The maximum number of counts for marking occurences, if this option is active.
|
||||
The default is 2000.
|
||||
|
||||
UseOldStyleBraceMatching
|
||||
Switch back to (not recommended) old style brace matching.
|
||||
The default is 0.
|
||||
|
||||
|
||||
Notepad2 already existing settings:
|
||||
-----------------------------------
|
||||
|
||||
86
src/Edit.c
86
src/Edit.c
@ -55,6 +55,7 @@ extern HINSTANCE g_hInstance;
|
||||
extern DWORD dwLastIOError;
|
||||
extern UINT cpLastFind;
|
||||
extern BOOL bReplaceInitialized;
|
||||
extern BOOL bUseOldStyleBraceMatching;
|
||||
|
||||
static EDITFINDREPLACE efrSave;
|
||||
static BOOL bSwitchedFindReplace = FALSE;
|
||||
@ -5256,15 +5257,46 @@ void CompleteWord(HWND hwnd, BOOL autoInsert)
|
||||
}
|
||||
|
||||
|
||||
BOOL __fastcall EditHighlightIfBrace(HWND hwnd, int iPos)
|
||||
{
|
||||
if (iPos < 0) {
|
||||
// clear indicator
|
||||
SendMessage(hwnd, SCI_BRACEBADLIGHT, (WPARAM)INVALID_POSITION, 0);
|
||||
SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0);
|
||||
if (!bUseOldStyleBraceMatching)
|
||||
SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 0, INDIC_NP3_BAD_BRACE);
|
||||
return TRUE;
|
||||
}
|
||||
char 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);
|
||||
if (!bUseOldStyleBraceMatching)
|
||||
SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, INDIC_NP3_MATCH_BRACE);
|
||||
}
|
||||
else {
|
||||
SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0);
|
||||
SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0);
|
||||
if (!bUseOldStyleBraceMatching)
|
||||
SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, INDIC_NP3_BAD_BRACE);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// EditMatchBrace()
|
||||
//
|
||||
void EditMatchBrace(HWND hwnd)
|
||||
{
|
||||
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);
|
||||
@ -5272,46 +5304,14 @@ void EditMatchBrace(HWND hwnd)
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
// Try one before
|
||||
else {
|
||||
int iPos = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0);
|
||||
|
||||
if (!EditHighlightIfBrace(hwnd, iPos)) {
|
||||
// try one before
|
||||
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_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);
|
||||
if (!EditHighlightIfBrace(hwnd, iPos)) {
|
||||
// clear mark
|
||||
EditHighlightIfBrace(hwnd, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5350,7 +5350,7 @@ void EditMarkAll(HWND hwnd, BOOL bMarkOccurrencesMatchCase, BOOL bMarkOccurrence
|
||||
iSelLength = (int)SendMessage(hwnd,SCI_GETSELTEXT,0,0);
|
||||
iSelCount = iSelEnd - iSelStart;
|
||||
|
||||
// clear existing indicator
|
||||
// clear existing marker indicators
|
||||
SendMessage(hwnd, SCI_SETINDICATORCURRENT, INDIC_NP3_MARK_OCCURANCE, 0);
|
||||
SendMessage(hwnd, SCI_INDICATORCLEARRANGE, 0, iTextLen);
|
||||
|
||||
|
||||
@ -33,26 +33,30 @@
|
||||
extern WCHAR szIniFile[MAX_PATH];
|
||||
|
||||
#define IniGetString(lpSection,lpName,lpDefault,lpReturnedStr,nSize) \
|
||||
GetPrivateProfileString(lpSection,lpName,lpDefault,lpReturnedStr,nSize,szIniFile)
|
||||
GetPrivateProfileString(lpSection,lpName,(lpDefault),(lpReturnedStr),(nSize),szIniFile)
|
||||
#define IniGetInt(lpSection,lpName,nDefault) \
|
||||
GetPrivateProfileInt(lpSection,lpName,nDefault,szIniFile)
|
||||
GetPrivateProfileInt(lpSection,lpName,(nDefault),szIniFile)
|
||||
#define IniGetBool(lpSection,lpName,nDefault) \
|
||||
(GetPrivateProfileInt(lpSection,lpName,(int)(nDefault),szIniFile) ? TRUE : FALSE)
|
||||
#define IniSetString(lpSection,lpName,lpString) \
|
||||
WritePrivateProfileString(lpSection,lpName,lpString,szIniFile)
|
||||
WritePrivateProfileString(lpSection,lpName,(lpString),szIniFile)
|
||||
#define IniDeleteSection(lpSection) \
|
||||
WritePrivateProfileSection(lpSection,NULL,szIniFile)
|
||||
__inline BOOL IniSetInt(LPCWSTR lpSection, LPCWSTR lpName, int i)
|
||||
{
|
||||
WCHAR tch[32] = { L'\0' }; StringCchPrintf(tch, COUNTOF(tch), L"%i", i); return IniSetString(lpSection, lpName, tch);
|
||||
}
|
||||
#define IniSetBool(lpSection,lpName,nValue) \
|
||||
IniSetInt(lpSection,lpName,((nValue) ? 1 : 0))
|
||||
#define LoadIniSection(lpSection,lpBuf,cchBuf) \
|
||||
GetPrivateProfileSection(lpSection,lpBuf,cchBuf,szIniFile)
|
||||
GetPrivateProfileSection(lpSection,lpBuf,(cchBuf),szIniFile)
|
||||
#define SaveIniSection(lpSection,lpBuf) \
|
||||
WritePrivateProfileSection(lpSection,lpBuf,szIniFile)
|
||||
int IniSectionGetString(LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, int);
|
||||
int IniSectionGetInt(LPCWSTR, LPCWSTR, int);
|
||||
UINT IniSectionGetUInt(LPCWSTR, LPCWSTR, UINT);
|
||||
__inline BOOL IniSectionGetBool(LPCWSTR lpCachedIniSection, LPCWSTR lpName, BOOL bDefault) {
|
||||
return (IniSectionGetInt(lpCachedIniSection, lpName, (bDefault ? 1 : 0)) ? TRUE : FALSE);
|
||||
return (IniSectionGetInt(lpCachedIniSection, lpName, ((bDefault) ? 1 : 0)) ? TRUE : FALSE);
|
||||
}
|
||||
BOOL IniSectionSetString(LPWSTR,LPCWSTR,LPCWSTR);
|
||||
__inline BOOL IniSectionSetInt(LPWSTR lpCachedIniSection,LPCWSTR lpName,int i) {
|
||||
|
||||
@ -152,6 +152,7 @@ int iMarkOccurrencesCount;
|
||||
int iMarkOccurrencesMaxCount;
|
||||
BOOL bMarkOccurrencesMatchCase;
|
||||
BOOL bMarkOccurrencesMatchWords;
|
||||
BOOL bUseOldStyleBraceMatching;
|
||||
BOOL bAutoCompleteWords;
|
||||
BOOL bAccelWordNavigation;
|
||||
BOOL bVirtualSpaceInRectSelection;
|
||||
@ -5984,6 +5985,8 @@ void LoadSettings()
|
||||
iMarkOccurrencesMaxCount = IniSectionGetInt(pIniSection,L"MarkOccurrencesMaxCount",2000);
|
||||
iMarkOccurrencesMaxCount = max(min(iMarkOccurrencesMaxCount,100000),2);
|
||||
|
||||
bUseOldStyleBraceMatching = IniSectionGetBool(pIniSection, L"UseOldStyleBraceMatching", FALSE);
|
||||
|
||||
LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection);
|
||||
|
||||
IniSectionGetString(pIniSection,L"BitmapDefault",L"",
|
||||
|
||||
33
src/Styles.c
33
src/Styles.c
@ -46,6 +46,9 @@ extern HINSTANCE g_hInstance;
|
||||
extern int iSciFontQuality;
|
||||
extern const int FontQuality[4];
|
||||
|
||||
extern BOOL bUseOldStyleBraceMatching;
|
||||
|
||||
|
||||
#define MULTI_STYLE(a,b,c,d) ((a)|(b<<8)|(c<<16)|(d<<24))
|
||||
|
||||
|
||||
@ -2999,18 +3002,24 @@ void Style_SetLexer(HWND hwnd,PEDITLEXER pLexNew)
|
||||
|
||||
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
|
||||
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 (bUseOldStyleBraceMatching) {
|
||||
Style_SetStyles(hwnd,lexDefault.Styles[2+iIdx].iStyle,lexDefault.Styles[2+iIdx].szValue); // brace light
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
if (bUseOldStyleBraceMatching) {
|
||||
Style_SetStyles(hwnd, lexDefault.Styles[3 + iIdx].iStyle, lexDefault.Styles[3 + iIdx].szValue); // brace bad
|
||||
}
|
||||
else {
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user