Skip to content

Commit

Permalink
Add Win32 Edit control's "Insert Unicode Control Character" function.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Oct 12, 2018
1 parent ab7b328 commit 462b1c5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
28 changes: 28 additions & 0 deletions scintilla/scripts/GenerateCharTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,33 @@ def MakeUTF8ClassifyMask(ch):
print('UTF8ClassifyTable:', len(UTF8ClassifyTable))
print('\n'.join(UTF8ClassifyTable))

def GenerateUnicodeControlCharacters():
ucc_table = [
"\u200E", # U+200E LRM Left-to-right mark
"\u200F", # U+200F RLM Right-to-left mark
"\u200D", # U+200D ZWJ Zero width joiner
"\u200C", # U+200C ZWNJ Zero width non-joiner
"\u202A", # U+202A LRE Start of left-to-right embedding
"\u202B", # U+202B RLE Start of right-to-left embedding
"\u202D", # U+202D LRO Start of left-to-right override
"\u202E", # U+202E RLO Start of right-to-left override
"\u202C", # U+202C PDF Pop directional formatting
"\u206E", # U+206E NADS National digit shapes substitution
"\u206F", # U+206F NODS Nominal (European) digit shapes
"\u206B", # U+206B ASS Activate symmetric swapping
"\u206A", # U+206A ISS Inhibit symmetric swapping
"\u206D", # U+206D AAFS Activate Arabic form shaping
"\u206C", # U+206C IAFS Inhibit Arabic form shaping
"\u001E", # U+001E RS Record Separator (Block separator)
"\u001F", # U+001F US Unit Separator (Segment separator)
]

print('UnicodeControlCharacters:')
for ucc in ucc_table:
utf8bytes = ucc.encode('utf-8')
utf8str = ''.join('\\x%02x' % b for b in utf8bytes)
print(utf8str, 'U+%04X' % ord(ucc))

if __name__ == '__main__':
GenerateUnicodeControlCharacters();
GenerateUTF8Table()
28 changes: 28 additions & 0 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6027,6 +6027,34 @@ 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);
}

//=============================================================================
//
// EditSortDlgProc()
Expand Down
1 change: 1 addition & 0 deletions src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ 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);
BOOL EditSortDlg(HWND hwnd, int *piSortFlags);
BOOL EditAlignDlg(HWND hwnd, int *piAlignMode);

Expand Down
20 changes: 20 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3288,6 +3288,26 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
}
break;

case IDM_INSERT_UNICODE_LRM:
case IDM_INSERT_UNICODE_RLM:
case IDM_INSERT_UNICODE_ZWJ:
case IDM_INSERT_UNICODE_ZWNJ:
case IDM_INSERT_UNICODE_LRE:
case IDM_INSERT_UNICODE_RLE:
case IDM_INSERT_UNICODE_LRO:
case IDM_INSERT_UNICODE_RLO:
case IDM_INSERT_UNICODE_PDF:
case IDM_INSERT_UNICODE_NADS:
case IDM_INSERT_UNICODE_NODS:
case IDM_INSERT_UNICODE_ASS:
case IDM_INSERT_UNICODE_ISS:
case IDM_INSERT_UNICODE_AAFS:
case IDM_INSERT_UNICODE_IAFS:
case IDM_INSERT_UNICODE_RS:
case IDM_INSERT_UNICODE_US:
EditInsertUnicodeControlCharacter(hwndEdit, LOWORD(wParam));
break;

case IDM_EDIT_INSERT_ENCODING: {
if (*mEncoding[iEncoding].pszParseNames) {
char msz[64];
Expand Down
24 changes: 22 additions & 2 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ BEGIN
POPUP "Copy to Clipboard"
BEGIN
MENUITEM "&File Name", CMD_COPYFILENAME_NOEXT
MENUITEM "File Name and &Ext\tShift+F9", CMD_COPYFILENAME
MENUITEM "File Name and &Ext.\tShift+F9", CMD_COPYFILENAME
MENUITEM "Full &Path Name\tAlt+Shift+F9", CMD_COPYPATHNAME
MENUITEM SEPARATOR
MENUITEM "Copy A&ll\tAlt+A", IDM_EDIT_COPYALL
Expand Down Expand Up @@ -248,9 +248,29 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "&HTML/XML Tags...\tAlt+X", IDM_EDIT_INSERT_XMLTAG
MENUITEM "New &GUID", IDM_EDIT_INSERT_GUID
POPUP "Unicode Control Character"
BEGIN
MENUITEM "LRM\t&Left-to-right mark", IDM_INSERT_UNICODE_LRM
MENUITEM "RLM\t&Right-to-left mark", IDM_INSERT_UNICODE_RLM
MENUITEM "ZWJ\tZero width &joiner", IDM_INSERT_UNICODE_ZWJ
MENUITEM "ZWNJ\tZero width &non-joiner", IDM_INSERT_UNICODE_ZWNJ
MENUITEM "LRE\tStart of left-to-right &embedding", IDM_INSERT_UNICODE_LRE
MENUITEM "RLE\tStart of right-to-left e&mbedding", IDM_INSERT_UNICODE_RLE
MENUITEM "LRO\tStart of left-to-right &override", IDM_INSERT_UNICODE_LRO
MENUITEM "RLO\tStart of right-to-left o&verride", IDM_INSERT_UNICODE_RLO
MENUITEM "PDF\t&Pop directional formatting", IDM_INSERT_UNICODE_PDF
MENUITEM "NADS\tN&ational digit shapes substitution",IDM_INSERT_UNICODE_NADS
MENUITEM "NODS\tNominal (European) &digit shapes", IDM_INSERT_UNICODE_NODS
MENUITEM "ASS\tActivate &symmetric swapping", IDM_INSERT_UNICODE_ASS
MENUITEM "ISS\tInhibit s&ymmetric swapping", IDM_INSERT_UNICODE_ISS
MENUITEM "AAFS\tActivate Arabic &form shaping", IDM_INSERT_UNICODE_AAFS
MENUITEM "IAFS\tInhibit Arabic form s&haping", IDM_INSERT_UNICODE_IAFS
MENUITEM "RS\tRecord Separator (&Block separator)", IDM_INSERT_UNICODE_RS
MENUITEM "US\tUnit Separator (&Segment separator)", IDM_INSERT_UNICODE_US
END
MENUITEM SEPARATOR
MENUITEM "&File Name", CMD_INSERTFILENAME_NOEXT
MENUITEM "File Name and &Ext\tCtrl+F9", IDM_EDIT_INSERT_FILENAME
MENUITEM "File Name and &Extension\tCtrl+F9",IDM_EDIT_INSERT_FILENAME
MENUITEM "Full &Path Name\tCtrl+Shift+F9", IDM_EDIT_INSERT_PATHNAME
MENUITEM SEPARATOR
MENUITEM "Current Date", IDM_EDIT_INSERT_LOC_DATE
Expand Down
18 changes: 18 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@
#define BME_EDIT_BOOKMARKNEXT 40255 // F2
#define BME_EDIT_BOOKMARKCLEAR 40256 // Alt+F2
#define BME_EDIT_BOOKMARKPREV 40257 // Shift+F2
// Insert Unicode Control Character
#define IDM_INSERT_UNICODE_LRM 40260
#define IDM_INSERT_UNICODE_RLM 40261
#define IDM_INSERT_UNICODE_ZWJ 40262
#define IDM_INSERT_UNICODE_ZWNJ 40263
#define IDM_INSERT_UNICODE_LRE 40264
#define IDM_INSERT_UNICODE_RLE 40265
#define IDM_INSERT_UNICODE_LRO 40266
#define IDM_INSERT_UNICODE_RLO 40267
#define IDM_INSERT_UNICODE_PDF 40268
#define IDM_INSERT_UNICODE_NADS 40269
#define IDM_INSERT_UNICODE_NODS 40270
#define IDM_INSERT_UNICODE_ASS 40271
#define IDM_INSERT_UNICODE_ISS 40272
#define IDM_INSERT_UNICODE_AAFS 40273
#define IDM_INSERT_UNICODE_IAFS 40274
#define IDM_INSERT_UNICODE_RS 40275
#define IDM_INSERT_UNICODE_US 40276
#define IDM_EDIT_UNDO 40300 // Alt+Back Ctrl+Z Ctrl+Shift+Y
#define IDM_EDIT_REDO 40301 // Ctrl+Y Ctrl+Shift+Z
#define IDM_EDIT_CUT 40302 // Ctrl+X Shift+Del
Expand Down

0 comments on commit 462b1c5

Please sign in to comment.