Merge pull request #1650 from RaiKoHoff/DevNewFeatures

Thin rectangular (multi) selection after toggling line-comment block
This commit is contained in:
Rainer Kottenhoff 2019-09-18 00:15:26 +02:00 committed by GitHub
commit 4ba918c76f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 58 deletions

View File

@ -1 +1 @@
2639
2640

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.19.916.2639"
version="5.19.917.2640"
type="win32"
/>
<description>Notepad3 BETA</description>

View File

@ -3181,8 +3181,9 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose)
//
void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart)
{
const DocPos iCurPos = SciCall_GetCurrentPos();
const DocPos iAnchorPos = SciCall_GetAnchor();
UNUSED(hwnd);
//const DocPos iCurPos = SciCall_GetCurrentPos();
//const DocPos iAnchorPos = SciCall_GetAnchor();
const DocPos iSelStart = SciCall_GetSelectionStart();
const DocPos iSelEnd = SciCall_GetSelectionEnd();
@ -3235,9 +3236,14 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart)
int iAction = 0;
for (DocLn iLine = iLineStart; iLine <= iLineEnd; iLine++)
UT_icd docpos_icd = { sizeof(DocPos), NULL, NULL, NULL };
UT_array* sel_positions = NULL;
utarray_new(sel_positions, &docpos_icd);
utarray_reserve(sel_positions, (int)(iLineEnd - iLineStart + 1));
for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine)
{
const DocPos iIndentPos = SciCall_GetLineIndentPosition(iLine);
DocPos const iIndentPos = SciCall_GetLineIndentPosition(iLine);
if (iIndentPos == SciCall_GetLineEndPosition(iLine)) {
// don't set comment char on "empty" (white-space only) lines
@ -3249,53 +3255,69 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart)
if (StrCmpNIA(tchBuf, mszComment, (int)cchComment) == 0)
{
// remove comment chars
DocPos const iSelPos = iIndentPos + cchComment;
switch (iAction) {
case 0:
iAction = 2;
case 2:
SciCall_SetTargetRange(iIndentPos, iIndentPos + cchComment);
SciCall_ReplaceTarget(0, "");
iSelEndOffset -= cchComment;
if (iLine == iLineStart) {
iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment);
}
break;
case 1:
break;
case 0:
iAction = 2;
case 2:
SciCall_SetTargetRange(iIndentPos, iSelPos);
SciCall_ReplaceTarget(0, "");
iSelEndOffset -= cchComment;
if (iLine == iLineStart) {
iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment);
}
utarray_push_back(sel_positions, &iIndentPos);
break;
case 1:
utarray_push_back(sel_positions, &iSelPos);
break;
}
}
else {
// set comment chars at indent pos
switch (iAction) {
case 0:
iAction = 1;
case 1:
case 0:
iAction = 1;
case 1:
{
SciCall_InsertText(SciCall_FindColumn(iLine, iCommentCol), mszComment);
DocPos const iPos = SciCall_FindColumn(iLine, iCommentCol);
SciCall_InsertText(iPos, mszComment);
iSelEndOffset += cchComment;
if (iLine == iLineStart) {
if (iLine == iLineStart) {
iSelStartOffset = (iCommentCol >= iSelBegCol) ? 0 : cchComment;
}
DocPos const iSelPos = iIndentPos + cchComment;
utarray_push_back(sel_positions, &iSelPos);
}
break;
case 2:
break;
case 2:
break;
}
}
}
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
_OBSERVE_NOTIFY_CHANGE_;
if (iCurPos < iAnchorPos) {
EditSetSelectionEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset, -1, -1);
}
else if (iCurPos > iAnchorPos) {
EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset, -1, -1);
}
else {
EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset, -1, -1);
//if (iCurPos < iAnchorPos) {
// EditSetSelectionEx(hwnd, iAnchorPos + iSelEndOffset, iCurPos + iSelStartOffset, -1, -1);
//}
//else if (iCurPos > iAnchorPos) {
// EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelEndOffset, -1, -1);
//}
//else {
// EditSetSelectionEx(hwnd, iAnchorPos + iSelStartOffset, iCurPos + iSelStartOffset, -1, -1);
//}
DocPos* p = (DocPos*)utarray_next(sel_positions, NULL);
if (p) { SciCall_SetSelection(*p, *p); }
while (p) {
p = (DocPos*)utarray_next(sel_positions, p);
if (p) { SciCall_AddSelection(*p, *p); }
}
utarray_free(sel_positions);
_OBSERVE_NOTIFY_CHANGE_;
_END_UNDO_ACTION_
}
@ -4271,8 +4293,13 @@ int CmpStdIRev(const void* s1, const void* s2) { return -1 * CmpStdI(s1, s2); }
// ----------------------------------------------------------------------------
int CmpLexicographical(const void *s1, const void *s2) {
int const cmp = wcscmp(((SORTLINE*)s1)->pwszSortEntry,((SORTLINE*)s2)->pwszSortEntry);
return (cmp) ? cmp : wcscmp(((SORTLINE*)s1)->pwszLine,((SORTLINE*)s2)->pwszLine);
LPCWSTR const pwszSE1 = ((SORTLINE*)s1)->pwszSortEntry;
LPCWSTR const pwszSE2 = ((SORTLINE*)s2)->pwszSortEntry;
if (pwszSE1 && pwszSE2) {
int const cmp = wcscmp(pwszSE1, pwszSE2);
return (cmp) ? cmp : wcscmp(((SORTLINE*)s1)->pwszLine, ((SORTLINE*)s2)->pwszLine);
}
return pwszSE1 ? -1 : (pwszSE2 ? 1 : 0);
}
//int CmpLexicographicalI(const void* s1, const void* s2) {
@ -4443,9 +4470,7 @@ void EditSortLines(HWND hwnd, int iSortFlags)
char* pmszResOffset = pmszResult;
char* pmszBuf = AllocMem(ichlMax + 1, HEAP_ZERO_MEMORY);
FNSTRCMP const pFctStrCmp = (iSortFlags & SORT_NOCASE) ?
((iSortFlags & SORT_LEXICOGRAPH) ? _wcsicmp : StrCmpI) :
((iSortFlags & SORT_LEXICOGRAPH) ? wcscmp : StrCmp);
FNSTRCMP const pFctStrCmp = (iSortFlags & SORT_NOCASE) ? StrCmpI : StrCmp;
bool bLastDup = false;
for (DocLn i = 0; i < iLineCount; ++i) {

View File

@ -5566,24 +5566,37 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case CMD_ESCAPE:
if (SciCall_CallTipActive() || SciCall_AutoCActive()) {
CancelCallTip();
SciCall_AutoCCancel();
}
else if (s_bIndicMultiEdit) {
SciCall_SetIndicatorCurrent(INDIC_NP3_MULTI_EDIT);
SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition());
s_bIndicMultiEdit = false;
}
else if (Settings.EscFunction == 1) {
SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (Settings.EscFunction == 2) {
CloseApplication(true);
}
else {
{
DocPos const iCurPos = SciCall_GetCurrentPos();
if (SciCall_CallTipActive() || SciCall_AutoCActive()) {
CancelCallTip();
SciCall_AutoCCancel();
break;
}
else if (s_bIndicMultiEdit) {
_BEGIN_UNDO_ACTION_
SciCall_SetIndicatorCurrent(INDIC_NP3_MULTI_EDIT);
SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition());
SciCall_ClearSelections();
_END_UNDO_ACTION_
s_bIndicMultiEdit = false;
}
else if (Settings.EscFunction == 1) {
SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
}
else if (Settings.EscFunction == 2) {
CloseApplication(true);
break;
}
if (!SciCall_IsSelectionEmpty()) {
DocPos const iCurPos = SciCall_GetCurrentPos();
_BEGIN_UNDO_ACTION_
EditSetSelectionEx(Globals.hwndEdit, iCurPos, iCurPos, -1, -1);
_END_UNDO_ACTION_
}
else {
EditSetSelectionEx(Globals.hwndEdit, iCurPos, iCurPos, -1, -1);
}
SciCall_Cancel();

View File

@ -169,6 +169,7 @@ DeclareSciCallR0(GetSelectionMode, GETSELECTIONMODE, int)
DeclareSciCallV1(SetSelectionMode, SETSELECTIONMODE, int, mode)
DeclareSciCallR0(GetSelections, GETSELECTIONS, DocPosU)
DeclareSciCallV2(SetSelection, SETSELECTION, DocPos, caretPos, DocPos, anchorPos)
DeclareSciCallV2(AddSelection, ADDSELECTION, DocPos, caretPos, DocPos, anchorPos)
DeclareSciCallR0(GetMainSelection, GETMAINSELECTION, DocPosU)
DeclareSciCallV1(SetMainSelection, SETMAINSELECTION, DocPosU, selnum)
DeclareSciCallR1(GetSelectionNCaret, GETSELECTIONNCARET, DocPos, DocPosU, selnum)

View File

@ -7,8 +7,8 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 19
#define VERSION_REV 916
#define VERSION_BUILD 2639
#define VERSION_REV 917
#define VERSION_BUILD 2640
#define SCINTILLA_VER 420
#define ONIGURUMA_REGEX_VER 6.9.3
#define UCHARDET_VER 2018.09.27