mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
Merge pull request #3121 from RaiKoHoff/Dev_Release
Change simple Line Comment Toggle behavior & move menu entry
This commit is contained in:
commit
72f2f82e91
@ -207,9 +207,9 @@ BEGIN
|
||||
BEGIN
|
||||
MENUITEM "&Indent", IDM_EDIT_INDENT
|
||||
MENUITEM "&Unindent", IDM_EDIT_UNINDENT
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Jump to Sele&ction Start\tCtrl+,", CMD_JUMP2SELSTART
|
||||
MENUITEM "Jump to Selectio&n End\tCtrl+.", CMD_JUMP2SELEND
|
||||
MENUITEM "Line &Comment (Toggle)\tCtrl+Q", IDM_EDIT_LINECOMMENT
|
||||
MENUITEM "Enable Line Comment &Block Edit", IDM_VIEW_EDIT_LINECOMMENT
|
||||
MENUITEM "St&ream Comment\tCtrl+Shift+Q", IDM_EDIT_STREAMCOMMENT
|
||||
MENUITEM SEPARATOR
|
||||
POPUP "&Enclose Selection"
|
||||
BEGIN
|
||||
@ -235,6 +235,9 @@ BEGIN
|
||||
MENUITEM "&Modify Lines...\tAlt+M", IDM_EDIT_MODIFYLINES
|
||||
MENUITEM "&Align Lines...\tAlt+J", IDM_EDIT_ALIGN
|
||||
MENUITEM "&Sort Lines...\tAlt+O", IDM_EDIT_SORTLINES
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Jump to Sele&ction Start\tCtrl+,", CMD_JUMP2SELSTART
|
||||
MENUITEM "Jump to Selectio&n End\tCtrl+.", CMD_JUMP2SELEND
|
||||
END
|
||||
POPUP "Con&vert"
|
||||
BEGIN
|
||||
@ -269,9 +272,6 @@ BEGIN
|
||||
MENUITEM "Time/Date (&Long Form)\tCtrl+Shift+F5", IDM_EDIT_INSERT_LONGDATE
|
||||
MENUITEM "Current &Timestamp", CMD_INSERT_TIMESTAMP
|
||||
MENUITEM "&Update Timestamps\tShift+F5", CMD_UPDATE_TIMESTAMPS
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Line &Comment (Toggle)\tCtrl+Q", IDM_EDIT_LINECOMMENT
|
||||
MENUITEM "St&ream Comment\tCtrl+Shift+Q", IDM_EDIT_STREAMCOMMENT
|
||||
END
|
||||
POPUP "&Miscellaneous"
|
||||
BEGIN
|
||||
@ -444,7 +444,6 @@ BEGIN
|
||||
MENUITEM "A&uto Complete Words", IDM_VIEW_AUTOCOMPLETEWORDS
|
||||
MENUITEM "Auto Complete Lexer-&Key-Words", IDM_VIEW_AUTOCLEXKEYWORDS
|
||||
MENUITEM "Accelerated Word Navi&gation\tCtrl+Alt+A", IDM_VIEW_ACCELWORDNAV
|
||||
MENUITEM "Enable Line Comment &Block Edit", IDM_VIEW_EDIT_LINECOMMENT
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Single &File Instance", IDM_VIEW_SINGLEFILEINSTANCE
|
||||
MENUITEM "File &Change Notification...\tAlt+F5", IDM_VIEW_CHANGENOTIFY
|
||||
|
||||
26
src/Edit.c
26
src/Edit.c
@ -3330,11 +3330,17 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
int iAction = 0;
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
int iAction = 0;
|
||||
bool const bKeepActionOf1stLine = false;
|
||||
|
||||
for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine) {
|
||||
|
||||
if (!bKeepActionOf1stLine) {
|
||||
iAction = 0;
|
||||
}
|
||||
|
||||
DocPos const iIndentPos = SciCall_GetLineIndentPosition(iLine);
|
||||
|
||||
if (iIndentPos == SciCall_GetLineEndPosition(iLine)) {
|
||||
@ -3352,7 +3358,7 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
iAction = 2;
|
||||
case 2:
|
||||
SciCall_SetTargetRange(iIndentPos, iSelPos);
|
||||
SciCall_ReplaceTarget(0, "");
|
||||
SciCall_ReplaceTarget(-1, "");
|
||||
iSelEndOffset -= cchComment;
|
||||
if (iLine == iLineStart) {
|
||||
iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment);
|
||||
@ -3369,7 +3375,7 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
iAction = 2;
|
||||
case 2:
|
||||
SciCall_SetTargetRange(iIndentPos, iSelPos);
|
||||
SciCall_ReplaceTarget(0, "");
|
||||
SciCall_ReplaceTarget(-1, "");
|
||||
iSelEndOffset -= cchPrefix;
|
||||
if (iLine == iLineStart) {
|
||||
iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchPrefix);
|
||||
@ -3462,8 +3468,6 @@ void EditToggleLineCommentsExtended(HWND hwnd, LPCWSTR pwszComment, bool bInsert
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
int iAction = 0;
|
||||
|
||||
UT_icd docpos_icd = { sizeof(DocPos), NULL, NULL, NULL };
|
||||
UT_array* sel_positions = NULL;
|
||||
utarray_new(sel_positions, &docpos_icd);
|
||||
@ -3471,7 +3475,15 @@ void EditToggleLineCommentsExtended(HWND hwnd, LPCWSTR pwszComment, bool bInsert
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
int iAction = 0;
|
||||
bool const bKeepActionOf1stLine = true;
|
||||
|
||||
for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine) {
|
||||
|
||||
if (!bKeepActionOf1stLine) {
|
||||
iAction = 0;
|
||||
}
|
||||
|
||||
DocPos const iIndentPos = SciCall_GetLineIndentPosition(iLine);
|
||||
|
||||
if (iIndentPos == SciCall_GetLineEndPosition(iLine)) {
|
||||
@ -3489,7 +3501,7 @@ void EditToggleLineCommentsExtended(HWND hwnd, LPCWSTR pwszComment, bool bInsert
|
||||
iAction = 2;
|
||||
case 2:
|
||||
SciCall_SetTargetRange(iIndentPos, iSelPos);
|
||||
SciCall_ReplaceTarget(0, "");
|
||||
SciCall_ReplaceTarget(-1, "");
|
||||
utarray_push_back(sel_positions, &iIndentPos);
|
||||
break;
|
||||
case 1:
|
||||
|
||||
290
src/Notepad3.c
290
src/Notepad3.c
@ -3465,6 +3465,152 @@ LRESULT MsgExitMenuLoop(HWND hwnd, WPARAM wParam)
|
||||
}
|
||||
|
||||
|
||||
static void _GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen) {
|
||||
|
||||
if (beg_out && end_out && maxlen) {
|
||||
|
||||
switch (SciCall_GetLexer()) {
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_CPP:
|
||||
case SCLEX_CSS:
|
||||
case SCLEX_D: // L"/+", L"+/" could also be used instead
|
||||
case SCLEX_DART:
|
||||
case SCLEX_HTML:
|
||||
case SCLEX_JSON:
|
||||
case SCLEX_KOTLIN:
|
||||
case SCLEX_NSIS:
|
||||
case SCLEX_RUST:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
case SCLEX_XML:
|
||||
StringCchCopy(beg_out, maxlen, L"/*");
|
||||
StringCchCopy(end_out, maxlen, L"*/");
|
||||
break;
|
||||
case SCLEX_INNOSETUP:
|
||||
case SCLEX_PASCAL:
|
||||
StringCchCopy(beg_out, maxlen, L"{");
|
||||
StringCchCopy(end_out, maxlen, L"}");
|
||||
break;
|
||||
case SCLEX_LUA:
|
||||
StringCchCopy(beg_out, maxlen, L"--[[");
|
||||
StringCchCopy(end_out, maxlen, L"]]");
|
||||
break;
|
||||
case SCLEX_COFFEESCRIPT:
|
||||
StringCchCopy(beg_out, maxlen, L"###");
|
||||
StringCchCopy(end_out, maxlen, L"###");
|
||||
break;
|
||||
case SCLEX_MATLAB:
|
||||
StringCchCopy(beg_out, maxlen, L"%{");
|
||||
StringCchCopy(end_out, maxlen, L"%}");
|
||||
break;
|
||||
// ------------------
|
||||
case SCLEX_NULL:
|
||||
case SCLEX_AHKL:
|
||||
case SCLEX_ASM:
|
||||
case SCLEX_AU3:
|
||||
case SCLEX_BASH:
|
||||
case SCLEX_BATCH:
|
||||
case SCLEX_CMAKE:
|
||||
case SCLEX_CONF:
|
||||
case SCLEX_DIFF:
|
||||
case SCLEX_LATEX:
|
||||
case SCLEX_MAKEFILE:
|
||||
case SCLEX_MARKDOWN:
|
||||
case SCLEX_NIM:
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_REGISTRY:
|
||||
case SCLEX_RUBY:
|
||||
case SCLEX_TCL:
|
||||
case SCLEX_TOML:
|
||||
case SCLEX_VB:
|
||||
case SCLEX_VBSCRIPT:
|
||||
case SCLEX_YAML:
|
||||
default:
|
||||
StringCchCopy(beg_out, maxlen, L"");
|
||||
StringCchCopy(end_out, maxlen, L"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool _GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
{
|
||||
if (pre_out && maxlen) {
|
||||
|
||||
switch (SciCall_GetLexer()) {
|
||||
case SCLEX_CPP:
|
||||
case SCLEX_D:
|
||||
case SCLEX_DART:
|
||||
case SCLEX_HTML:
|
||||
case SCLEX_JSON:
|
||||
case SCLEX_KOTLIN:
|
||||
case SCLEX_PASCAL:
|
||||
case SCLEX_RUST:
|
||||
case SCLEX_XML:
|
||||
StringCchCopy(pre_out, maxlen, L"//");
|
||||
return false;
|
||||
case SCLEX_VB:
|
||||
case SCLEX_VBSCRIPT:
|
||||
StringCchCopy(pre_out, maxlen, L"'");
|
||||
return false;
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_BASH:
|
||||
case SCLEX_CMAKE:
|
||||
case SCLEX_COFFEESCRIPT:
|
||||
case SCLEX_CONF:
|
||||
case SCLEX_MAKEFILE:
|
||||
case SCLEX_NIM:
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_RUBY:
|
||||
case SCLEX_TCL:
|
||||
case SCLEX_TOML:
|
||||
case SCLEX_YAML:
|
||||
StringCchCopy(pre_out, maxlen, L"#");
|
||||
return true;
|
||||
case SCLEX_AHKL:
|
||||
case SCLEX_ASM:
|
||||
case SCLEX_AU3:
|
||||
case SCLEX_INNOSETUP:
|
||||
case SCLEX_NSIS: // "#" could also be used instead
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_REGISTRY:
|
||||
StringCchCopy(pre_out, maxlen, L";");
|
||||
return true;
|
||||
case SCLEX_LUA:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
StringCchCopy(pre_out, maxlen, L"--");
|
||||
return true;
|
||||
case SCLEX_BATCH: // "::" could also be used instead
|
||||
StringCchCopy(pre_out, maxlen, L"rem ");
|
||||
return true;
|
||||
case SCLEX_LATEX:
|
||||
case SCLEX_MATLAB:
|
||||
StringCchCopy(pre_out, maxlen, L"%");
|
||||
return true;
|
||||
// ------------------
|
||||
case SCLEX_NULL:
|
||||
case SCLEX_CSS:
|
||||
case SCLEX_DIFF:
|
||||
case SCLEX_MARKDOWN:
|
||||
default:
|
||||
StringCchCopy(pre_out, maxlen, L"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// MsgInitMenu() - Handles WM_INITMENU
|
||||
@ -3638,17 +3784,12 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
EnableCmd(hmenu, IDM_VIEW_SHOWEXCERPT, !se);
|
||||
|
||||
i = max_i(SCLEX_NULL, SciCall_GetLexer());
|
||||
WCHAR cmnt[8];
|
||||
_GetLineCommentStrg(cmnt, COUNTOF(cmnt));
|
||||
EnableCmd(hmenu, IDM_EDIT_LINECOMMENT, StrIsNotEmpty(cmnt) && !ro);
|
||||
|
||||
EnableCmd(hmenu, IDM_EDIT_LINECOMMENT,
|
||||
!(i == SCLEX_NULL || i == SCLEX_CSS || i == SCLEX_DIFF || i == SCLEX_MARKDOWN || i == SCLEX_JSON) && !ro);
|
||||
|
||||
EnableCmd(hmenu, IDM_EDIT_STREAMCOMMENT,
|
||||
!(i == SCLEX_NULL || i == SCLEX_VBSCRIPT || i == SCLEX_MAKEFILE || i == SCLEX_VB || i == SCLEX_ASM ||
|
||||
i == SCLEX_PERL || i == SCLEX_PYTHON || i == SCLEX_PROPERTIES || i == SCLEX_CONF ||
|
||||
i == SCLEX_POWERSHELL || i == SCLEX_BATCH || i == SCLEX_DIFF || i == SCLEX_BASH || i == SCLEX_TCL ||
|
||||
i == SCLEX_AU3 || i == SCLEX_LATEX || i == SCLEX_AHKL || i == SCLEX_RUBY || i == SCLEX_CMAKE || i == SCLEX_MARKDOWN ||
|
||||
i == SCLEX_YAML || i == SCLEX_REGISTRY || i == SCLEX_NIM || i == SCLEX_TOML) && !ro);
|
||||
_GetStreamCommentStrgs(cmnt, cmnt, COUNTOF(cmnt));
|
||||
EnableCmd(hmenu, IDM_EDIT_STREAMCOMMENT, StrIsNotEmpty(cmnt) && !ro);
|
||||
|
||||
EnableCmd(hmenu, CMD_INSERTNEWLINE, !ro);
|
||||
EnableCmd(hmenu, IDM_EDIT_INSERT_TAG, !ro);
|
||||
@ -4866,130 +5007,21 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
|
||||
case IDM_EDIT_LINECOMMENT: {
|
||||
switch (SciCall_GetLexer()) {
|
||||
case SCLEX_CPP:
|
||||
case SCLEX_D:
|
||||
case SCLEX_HTML:
|
||||
case SCLEX_PASCAL:
|
||||
case SCLEX_RUST:
|
||||
case SCLEX_XML:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"//", false);
|
||||
break;
|
||||
case SCLEX_VB:
|
||||
case SCLEX_VBSCRIPT:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"'", false);
|
||||
break;
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_BASH:
|
||||
case SCLEX_CMAKE:
|
||||
case SCLEX_COFFEESCRIPT:
|
||||
case SCLEX_CONF:
|
||||
case SCLEX_MAKEFILE:
|
||||
case SCLEX_NIM:
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_RUBY:
|
||||
case SCLEX_TCL:
|
||||
case SCLEX_TOML:
|
||||
case SCLEX_YAML:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"#", true);
|
||||
break;
|
||||
case SCLEX_AHKL:
|
||||
case SCLEX_ASM:
|
||||
case SCLEX_AU3:
|
||||
case SCLEX_INNOSETUP:
|
||||
case SCLEX_NSIS: // # could also be used instead
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_REGISTRY:
|
||||
EditToggleLineComments(Globals.hwndEdit, L";", true);
|
||||
break;
|
||||
case SCLEX_LUA:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"--", true);
|
||||
break;
|
||||
case SCLEX_BATCH:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"rem ", true);
|
||||
break;
|
||||
case SCLEX_LATEX:
|
||||
case SCLEX_MATLAB:
|
||||
EditToggleLineComments(Globals.hwndEdit, L"%", true);
|
||||
break;
|
||||
// ------------------
|
||||
case SCLEX_NULL:
|
||||
case SCLEX_CSS:
|
||||
case SCLEX_DIFF:
|
||||
case SCLEX_JSON:
|
||||
case SCLEX_MARKDOWN:
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
WCHAR comment[8] = { L'\0' };
|
||||
bool const bAtStart = _GetLineCommentStrg(comment, COUNTOF(comment));
|
||||
if (StrIsNotEmpty(comment)) {
|
||||
EditToggleLineComments(Globals.hwndEdit, comment, bAtStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IDM_EDIT_STREAMCOMMENT: {
|
||||
switch (SciCall_GetLexer()) {
|
||||
case SCLEX_D:
|
||||
//~EditEncloseSelection(Globals.hwndEdit, L"/+", L"+/");
|
||||
//~break;
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_CPP:
|
||||
case SCLEX_CSS:
|
||||
case SCLEX_HTML:
|
||||
case SCLEX_NSIS:
|
||||
case SCLEX_RUST:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
case SCLEX_XML:
|
||||
EditEncloseSelection(L"/*", L"*/");
|
||||
break;
|
||||
case SCLEX_INNOSETUP:
|
||||
case SCLEX_PASCAL:
|
||||
EditEncloseSelection(L"{", L"}");
|
||||
break;
|
||||
case SCLEX_LUA:
|
||||
EditEncloseSelection(L"--[[", L"]]");
|
||||
break;
|
||||
case SCLEX_COFFEESCRIPT:
|
||||
EditEncloseSelection(L"###", L"###");
|
||||
break;
|
||||
case SCLEX_MATLAB:
|
||||
EditEncloseSelection(L"%{", L"%}");
|
||||
break;
|
||||
// ------------------
|
||||
case SCLEX_NULL:
|
||||
case SCLEX_AHKL:
|
||||
case SCLEX_ASM:
|
||||
case SCLEX_AU3:
|
||||
case SCLEX_BASH:
|
||||
case SCLEX_BATCH:
|
||||
case SCLEX_CMAKE:
|
||||
case SCLEX_CONF:
|
||||
case SCLEX_DIFF:
|
||||
case SCLEX_JSON:
|
||||
case SCLEX_LATEX:
|
||||
case SCLEX_MAKEFILE:
|
||||
case SCLEX_MARKDOWN:
|
||||
case SCLEX_NIM:
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_REGISTRY:
|
||||
case SCLEX_RUBY:
|
||||
case SCLEX_TCL:
|
||||
case SCLEX_TOML:
|
||||
case SCLEX_VB:
|
||||
case SCLEX_VBSCRIPT:
|
||||
case SCLEX_YAML:
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
WCHAR cmnt_beg[8] = { L'\0' };
|
||||
WCHAR cmnt_end[8] = { L'\0' };
|
||||
_GetStreamCommentStrgs(cmnt_beg, cmnt_end, COUNTOF(cmnt_beg));
|
||||
if (StrIsNotEmpty(cmnt_beg)) {
|
||||
EditEncloseSelection(cmnt_beg, cmnt_end);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user