Fix "Single Line Uncomment" uncomments an extra line issue
Fix from: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12829#issuecomment-1737330242 Fix #12829
This commit is contained in:
parent
c4c1089231
commit
7bbe4d1ff8
|
@ -8468,7 +8468,7 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
|
||||||
generic_string symbol;
|
generic_string symbol;
|
||||||
|
|
||||||
const int charbufLen = 10;
|
const int charbufLen = 10;
|
||||||
TCHAR charbuf[charbufLen];
|
TCHAR charbuf[charbufLen]{};
|
||||||
|
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
|
|
||||||
|
@ -8605,13 +8605,13 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
|
||||||
//-- Ok, there are valid start-comment and valid end-comment around the caret-position.
|
//-- Ok, there are valid start-comment and valid end-comment around the caret-position.
|
||||||
// Now, un-comment stream-comment:
|
// Now, un-comment stream-comment:
|
||||||
retVal = true;
|
retVal = true;
|
||||||
intptr_t startCommentLength = start_comment_length;
|
intptr_t startCommentLength = static_cast<intptr_t>(start_comment_length);
|
||||||
intptr_t endCommentLength = end_comment_length;
|
intptr_t endCommentLength = static_cast<intptr_t>(end_comment_length);
|
||||||
|
|
||||||
//-- First delete end-comment, so that posStartCommentBefore does not change!
|
//-- First delete end-comment, so that posStartCommentBefore does not change!
|
||||||
//-- Get character before end-comment to decide, if there is a white character before the end-comment, which will be removed too!
|
//-- Get character before end-comment to decide, if there is a white character before the end-comment, which will be removed too!
|
||||||
_pEditView->getGenericText(charbuf, charbufLen, posEndComment - 1, posEndComment);
|
_pEditView->getGenericText(charbuf, charbufLen, posEndComment - 1, posEndComment);
|
||||||
if (wcsncmp(charbuf, white_space.c_str(), white_space.length()) == 0)
|
if (wcsnicmp(charbuf, white_space.c_str(), white_space.length()) == 0)
|
||||||
{
|
{
|
||||||
endCommentLength += 1;
|
endCommentLength += 1;
|
||||||
posEndComment -= 1;
|
posEndComment -= 1;
|
||||||
|
@ -8623,7 +8623,7 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
|
||||||
|
|
||||||
//-- Get character after start-comment to decide, if there is a white character after the start-comment, which will be removed too!
|
//-- Get character after start-comment to decide, if there is a white character after the start-comment, which will be removed too!
|
||||||
_pEditView->getGenericText(charbuf, charbufLen, posStartComment + startCommentLength, posStartComment + startCommentLength + 1);
|
_pEditView->getGenericText(charbuf, charbufLen, posStartComment + startCommentLength, posStartComment + startCommentLength + 1);
|
||||||
if (wcsncmp(charbuf, white_space.c_str(), white_space.length()) == 0)
|
if (wcsnicmp(charbuf, white_space.c_str(), white_space.length()) == 0)
|
||||||
startCommentLength += 1;
|
startCommentLength += 1;
|
||||||
|
|
||||||
//-- Delete starting stream-comment string ---------
|
//-- Delete starting stream-comment string ---------
|
||||||
|
@ -8637,20 +8637,20 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
|
||||||
if (selectionStart > posStartComment)
|
if (selectionStart > posStartComment)
|
||||||
{
|
{
|
||||||
if (selectionStart >= posStartComment + startCommentLength)
|
if (selectionStart >= posStartComment + startCommentLength)
|
||||||
selectionStartMove = -startCommentLength;
|
selectionStartMove = -static_cast<intptr_t>(startCommentLength);
|
||||||
else
|
else
|
||||||
selectionStartMove = -selectionStart - posStartComment;
|
selectionStartMove = -static_cast<intptr_t>(selectionStart - posStartComment);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
selectionStartMove = 0;
|
selectionStartMove = 0;
|
||||||
|
|
||||||
// selectionEnd
|
// selectionEnd
|
||||||
if (selectionEnd >= posEndComment + endCommentLength)
|
if (selectionEnd >= posEndComment + endCommentLength)
|
||||||
selectionEndMove = -startCommentLength+endCommentLength;
|
selectionEndMove = -static_cast<intptr_t>(startCommentLength + endCommentLength);
|
||||||
else if (selectionEnd <= posEndComment)
|
else if (selectionEnd <= posEndComment)
|
||||||
selectionEndMove = -startCommentLength;
|
selectionEndMove = -static_cast<intptr_t>(startCommentLength);
|
||||||
else
|
else
|
||||||
selectionEndMove = -startCommentLength + (selectionEnd - posEndComment);
|
selectionEndMove = -static_cast<intptr_t>(startCommentLength + (selectionEnd - posEndComment));
|
||||||
|
|
||||||
//-- Reset selection of text without deleted stream-comment-string
|
//-- Reset selection of text without deleted stream-comment-string
|
||||||
if (move_caret)
|
if (move_caret)
|
||||||
|
@ -8663,9 +8663,7 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment)
|
||||||
{
|
{
|
||||||
_pEditView->execute(SCI_SETSEL, selectionStart + selectionStartMove, selectionEnd + selectionEndMove);
|
_pEditView->execute(SCI_SETSEL, selectionStart + selectionStartMove, selectionEnd + selectionEndMove);
|
||||||
}
|
}
|
||||||
}
|
} while (1); //do as long as stream-comments are within selection
|
||||||
while (1); //do as long as stream-comments are within selection
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notepad_plus::monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting)
|
void Notepad_plus::monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting)
|
||||||
|
|
Loading…
Reference in New Issue