Permalink
Browse files

Show Unicode Control Character.

  • Loading branch information...
zufuliu committed Oct 12, 2018
1 parent 046b61d commit 4868ac9cf0bf39534e25f4c44734cb451d3f2a7c
Showing with 63 additions and 27 deletions.
  1. +45 −26 src/Edit.c
  2. +2 −1 src/Edit.h
  3. +14 −0 src/Notepad2.c
  4. +1 −0 src/Notepad2.rc
  5. +1 −0 src/resource.h
@@ -6027,32 +6027,51 @@ BOOL EditInsertTagDlg(HWND hwnd, LPWSTR pwszOpen, LPWSTR pwszClose) {
return iResult == IDOK;
}
void EditInsertUnicodeControlCharacter(HWND hwnd, int ucc) {
// scintilla/scripts/GenerateCharTable.py
static LPCSTR const ucc_table[] = {
"\xe2\x80\x8e", // U+200E LRM Left-to-right mark
"\xe2\x80\x8f", // U+200F RLM Right-to-left mark
"\xe2\x80\x8d", // U+200D ZWJ Zero width joiner
"\xe2\x80\x8c", // U+200C ZWNJ Zero width non-joiner
"\xe2\x80\xaa", // U+202A LRE Start of left-to-right embedding
"\xe2\x80\xab", // U+202B RLE Start of right-to-left embedding
"\xe2\x80\xad", // U+202D LRO Start of left-to-right override
"\xe2\x80\xae", // U+202E RLO Start of right-to-left override
"\xe2\x80\xac", // U+202C PDF Pop directional formatting
"\xe2\x81\xae", // U+206E NADS National digit shapes substitution
"\xe2\x81\xaf", // U+206F NODS Nominal (European) digit shapes
"\xe2\x81\xab", // U+206B ASS Activate symmetric swapping
"\xe2\x81\xaa", // U+206A ISS Inhibit symmetric swapping
"\xe2\x81\xad", // U+206D AAFS Activate Arabic form shaping
"\xe2\x81\xac", // U+206C IAFS Inhibit Arabic form shaping
"\x1e", // U+001E RS Record Separator (Block separator)
"\x1f", // U+001F US Unit Separator (Segment separator)
};
ucc = ucc - IDM_INSERT_UNICODE_LRM;
LPCSTR lpsz = ucc_table[ucc];
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)lpsz);
typedef struct UnicodeControlCharacter {
LPCSTR uccUTF8;
LPCSTR representation;
} UnicodeControlCharacter;
// scintilla/scripts/GenerateCharTable.py
static const UnicodeControlCharacter kUnicodeControlCharacterTable[] = {
{ "\xe2\x80\x8e", "LRM" }, // U+200E LRM Left-to-right mark
{ "\xe2\x80\x8f", "RLM" }, // U+200F RLM Right-to-left mark
{ "\xe2\x80\x8d", "ZWJ" }, // U+200D ZWJ Zero width joiner
{ "\xe2\x80\x8c", "ZWNJ" }, // U+200C ZWNJ Zero width non-joiner
{ "\xe2\x80\xaa", "LRE" }, // U+202A LRE Start of left-to-right embedding
{ "\xe2\x80\xab", "RLE" }, // U+202B RLE Start of right-to-left embedding
{ "\xe2\x80\xad", "LRO" }, // U+202D LRO Start of left-to-right override
{ "\xe2\x80\xae", "RLO" }, // U+202E RLO Start of right-to-left override
{ "\xe2\x80\xac", "PDF" }, // U+202C PDF Pop directional formatting
{ "\xe2\x81\xae", "NADS" }, // U+206E NADS National digit shapes substitution
{ "\xe2\x81\xaf", "NODS" }, // U+206F NODS Nominal (European) digit shapes
{ "\xe2\x81\xab", "ASS" }, // U+206B ASS Activate symmetric swapping
{ "\xe2\x81\xaa", "ISS" }, // U+206A ISS Inhibit symmetric swapping
{ "\xe2\x81\xad", "AAFS" }, // U+206D AAFS Activate Arabic form shaping
{ "\xe2\x81\xac", "IAFS" }, // U+206C IAFS Inhibit Arabic form shaping
// built-in C0 control set
{ "\x1e", NULL }, // U+001E RS Record Separator (Block separator)
{ "\x1f", NULL }, // U+001F US Unit Separator (Segment separator)
};
void EditInsertUnicodeControlCharacter(HWND hwnd, int menu) {
menu = menu - IDM_INSERT_UNICODE_LRM;
const UnicodeControlCharacter ucc = kUnicodeControlCharacterTable[menu];
SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ucc.uccUTF8);
}
void EditShowUnicodeControlCharacter(HWND hwnd, BOOL bShow) {
for (UINT i = 0; i < COUNTOF(kUnicodeControlCharacterTable); i++) {
const UnicodeControlCharacter ucc = kUnicodeControlCharacterTable[i];
if (StrIsEmptyA(ucc.representation)) {
continue;
}
if (bShow) {
SendMessage(hwnd, SCI_SETREPRESENTATION, (WPARAM)ucc.uccUTF8, (LPARAM)ucc.representation);
} else {
SendMessage(hwnd, SCI_CLEARREPRESENTATION, (WPARAM)ucc.uccUTF8, 0);
}
}
}
//=============================================================================
@@ -131,7 +131,8 @@ BOOL EditLineNumDlg(HWND hwnd);
BOOL EditModifyLinesDlg(HWND hwnd, LPWSTR pwsz1, LPWSTR pwsz2);
BOOL EditEncloseSelectionDlg(HWND hwnd, LPWSTR pwszOpen, LPWSTR pwszClose);
BOOL EditInsertTagDlg(HWND hwnd, LPWSTR pwszOpen, LPWSTR pwszClose);
void EditInsertUnicodeControlCharacter(HWND hwnd, int ucc);
void EditInsertUnicodeControlCharacter(HWND hwnd, int menu);
void EditShowUnicodeControlCharacter(HWND hwnd, BOOL bShow);
BOOL EditSortDlg(HWND hwnd, int *piSortFlags);
BOOL EditAlignDlg(HWND hwnd, int *piAlignMode);
@@ -117,6 +117,7 @@ int iWordWrapMode;
int iWordWrapIndent;
int iWordWrapSymbols;
BOOL bShowWordWrapSymbols;
BOOL bShowUnicodeControlCharacter;
BOOL bMatchBraces;
BOOL bAutoIndent;
BOOL bAutoCloseTags;
@@ -1578,6 +1579,10 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {
SetWrapIndentMode();
SetWrapVisualFlags();
if (bShowUnicodeControlCharacter) {
EditShowUnicodeControlCharacter(hwndEdit, TRUE);
}
// Long Lines
if (bMarkLongLines) {
SendMessage(hwndEdit, SCI_SETEDGEMODE, (iLongLineMode == EDGE_LINE) ? EDGE_LINE : EDGE_BACKGROUND, 0);
@@ -2369,6 +2374,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) {
CheckCmd(hmenu, IDM_VIEW_SHOWWHITESPACE, bViewWhiteSpace);
CheckCmd(hmenu, IDM_VIEW_SHOWEOLS, bViewEOLs);
CheckCmd(hmenu, IDM_VIEW_WORDWRAPSYMBOLS, bShowWordWrapSymbols);
CheckCmd(hmenu, IDM_VIEW_UNICODE_CONTROL_CHAR, bShowUnicodeControlCharacter);
#if NP2_ENABLE_SHOW_CALL_TIPS
CheckCmd(hmenu, IDM_VIEW_SHOWCALLTIPS, bShowCallTips);
#endif
@@ -4018,6 +4024,11 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
SetWrapVisualFlags();
break;
case IDM_VIEW_UNICODE_CONTROL_CHAR:
bShowUnicodeControlCharacter = !bShowUnicodeControlCharacter;
EditShowUnicodeControlCharacter(hwndEdit, bShowUnicodeControlCharacter);
break;
#if NP2_ENABLE_SHOW_CALL_TIPS
case IDM_VIEW_SHOWCALLTIPS:
bShowCallTips = !bShowCallTips;
@@ -5369,6 +5380,8 @@ void LoadSettings(void) {
iWordWrapSymbols = clamp_i(iWordWrapSymbols % 10, 0, 2) + clamp_i((iWordWrapSymbols % 100 - iWordWrapSymbols % 10) / 10, 0, 2) * 10;
bShowWordWrapSymbols = IniSectionGetBool(pIniSection, L"ShowWordWrapSymbols", 0);
bShowUnicodeControlCharacter = IniSectionGetBool(pIniSection, L"ShowUnicodeControlCharacter", 0);
bMatchBraces = IniSectionGetBool(pIniSection, L"MatchBraces", 1);
bHighlightCurrentLine = IniSectionGetBool(pIniSection, L"HighlightCurrentLine", 0);
bShowIndentGuides = IniSectionGetBool(pIniSection, L"ShowIndentGuides", 0);
@@ -5675,6 +5688,7 @@ void SaveSettings(BOOL bSaveSettingsNow) {
IniSectionSetIntEx(pIniSection, L"WordWrapIndent", iWordWrapIndent, 0);
IniSectionSetIntEx(pIniSection, L"WordWrapSymbols", iWordWrapSymbols, 22);
IniSectionSetBoolEx(pIniSection, L"ShowWordWrapSymbols", bShowWordWrapSymbols, 0);
IniSectionSetBoolEx(pIniSection, L"ShowUnicodeControlCharacter", bShowUnicodeControlCharacter, 0);
IniSectionSetBoolEx(pIniSection, L"MatchBraces", bMatchBraces, 1);
IniSectionSetBoolEx(pIniSection, L"HighlightCurrentLine", bHighlightCurrentLine, 0);
IniSectionSetBoolEx(pIniSection, L"ShowIndentGuides", bShowIndentGuides, 0);
@@ -372,6 +372,7 @@ BEGIN
MENUITEM "Show &Whitespace\tCtrl+Shift+8", IDM_VIEW_SHOWWHITESPACE
MENUITEM "Show Line &Endings\tCtrl+Shift+9", IDM_VIEW_SHOWEOLS
MENUITEM "Show Wrap S&ymbols\tCtrl+Shift+0", IDM_VIEW_WORDWRAPSYMBOLS
MENUITEM "Unicode Control Character", IDM_VIEW_UNICODE_CONTROL_CHAR
//MENUITEM "Show Call Tips", IDM_VIEW_SHOWCALLTIPS
MENUITEM SEPARATOR
MENUITEM "Visual &Brace Matching\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES
@@ -437,6 +437,7 @@
#define IDM_SET_BIDIRECTIONAL_NONE 40060
#define IDM_SET_BIDIRECTIONAL_L2R 40061
#define IDM_SET_BIDIRECTIONAL_R2L 40062
#define IDM_VIEW_UNICODE_CONTROL_CHAR 40063
#define IDM_VIEW_FONTQUALITY_DEFAULT 40065
#define IDM_VIEW_FONTQUALITY_NONE 40066
#define IDM_VIEW_FONTQUALITY_STANDARD 40067

0 comments on commit 4868ac9

Please sign in to comment.