From 4a22ba160e08d596d1fe18f0506fe802c55b044b Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 29 Jan 2018 01:37:50 +0100 Subject: [PATCH] + fix: preserve selection on Line Comment toggle --- src/Edit.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index ffd99cd51..849c1f90d 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -2945,10 +2945,7 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, BOOL bInsertAtStart) if (iLineIndentPos != iLineEndPos) { const int iIndentColumn = SciCall_GetColumn(iLineIndentPos); iCommentCol = min(iCommentCol, iIndentColumn); - if ((iLine == iLineStart) && (iIndentColumn > iSelBegCol)) { iSelStartOffset = 0; } } - else - if (iLine == iLineStart) { iSelStartOffset = 0; } } } @@ -2978,7 +2975,9 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, BOOL bInsertAtStart) SendMessage(hwnd, SCI_SETTARGETRANGE, iIndentPos, iIndentPos + cchComment); SendMessage(hwnd, SCI_REPLACETARGET, 0, (LPARAM)""); iSelEndOffset -= cchComment; - if (iLine == iLineStart) { iSelStartOffset = (0 - iSelStartOffset); } + if (iLine == iLineStart) { + iSelStartOffset = (iSelStart == SciCall_PositionFromLine(iLine)) ? 0 : (0 - cchComment); + } break; case 1: break; @@ -2993,6 +2992,9 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, BOOL bInsertAtStart) const int iCommentPos = (int)SendMessage(hwnd, SCI_FINDCOLUMN, (WPARAM)iLine, (LPARAM)iCommentCol); SendMessage(hwnd, SCI_INSERTTEXT, (WPARAM)iCommentPos, (LPARAM)mszComment); iSelEndOffset += cchComment; + if (iLine == iLineStart) { + iSelStartOffset = (iCommentCol >= iSelBegCol) ? 0 : cchComment; + } } break; case 2: