Fix trim operations for selection lines not working issue
Fix #12602, fix #12658, close #12655
This commit is contained in:
parent
ad6b9085dd
commit
3f0f6a2295
|
@ -1473,21 +1473,65 @@ void Notepad_plus::wsTabConvert(spaceTab whichWay)
|
|||
|
||||
void Notepad_plus::doTrim(trimOp whichPart)
|
||||
{
|
||||
// whichPart : line head or line tail
|
||||
// whichPart : line head or line tail or line both
|
||||
FindOption env;
|
||||
if (whichPart == lineHeader)
|
||||
{
|
||||
env._str2Search = TEXT("^[ ]+");
|
||||
env._str2Search = TEXT("^[\\t ]+");
|
||||
}
|
||||
else if (whichPart == lineTail)
|
||||
{
|
||||
env._str2Search = TEXT("[ ]+$");
|
||||
env._str2Search = TEXT("[\\t ]+$");
|
||||
}
|
||||
else if (whichPart == lineBoth)
|
||||
{
|
||||
env._str2Search = TEXT("^[\\t ]+|[\\t ]+$");
|
||||
}
|
||||
else
|
||||
return;
|
||||
env._str4Replace = TEXT("");
|
||||
env._searchType = FindRegex;
|
||||
_findReplaceDlg.processAll(ProcessReplaceAll, &env, true);
|
||||
env._searchType = FindRegex;
|
||||
auto mainSelAnchor = _pEditView->execute(SCI_GETANCHOR);
|
||||
auto mainSelCaretPos = _pEditView->execute(SCI_GETCURRENTPOS);
|
||||
auto rectSelAnchorVirt = _pEditView->execute(SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE);
|
||||
auto rectSelCaretVirt = _pEditView->execute(SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE);
|
||||
bool isRectSel = (_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN);
|
||||
bool isEntireDoc = (mainSelAnchor == mainSelCaretPos) && (rectSelAnchorVirt == rectSelCaretVirt);
|
||||
auto docLength = _pEditView->execute(SCI_GETLENGTH);
|
||||
// auto-expand of partially selected lines
|
||||
if (!isEntireDoc)
|
||||
{
|
||||
env._isInSelection = !isEntireDoc;
|
||||
auto startPos = _pEditView->execute(SCI_GETSELECTIONSTART);
|
||||
auto startLine = _pEditView->execute(SCI_LINEFROMPOSITION, startPos);
|
||||
auto endPos = _pEditView->execute(SCI_GETSELECTIONEND);
|
||||
auto endLine = _pEditView->execute(SCI_LINEFROMPOSITION, endPos);
|
||||
|
||||
if (startPos != _pEditView->execute(SCI_POSITIONFROMLINE, startLine))
|
||||
startPos = _pEditView->execute(SCI_POSITIONFROMLINE, startLine);
|
||||
|
||||
if (endPos != _pEditView->execute(SCI_POSITIONFROMLINE, endLine) && endPos < _pEditView->execute(SCI_GETLINEENDPOSITION, endLine))
|
||||
endPos = _pEditView->execute(SCI_GETLINEENDPOSITION, endLine);
|
||||
|
||||
_pEditView->execute(SCI_SETSEL, startPos, endPos);
|
||||
}
|
||||
_findReplaceDlg.processAll(ProcessReplaceAll, &env, isEntireDoc);
|
||||
// restore original selection if nothing has changed
|
||||
if (!isEntireDoc && (docLength == _pEditView->execute(SCI_GETLENGTH)))
|
||||
{
|
||||
if (isRectSel)
|
||||
{
|
||||
_pEditView->execute(SCI_SETRECTANGULARSELECTIONANCHOR, mainSelAnchor);
|
||||
_pEditView->execute(SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, rectSelAnchorVirt);
|
||||
_pEditView->execute(SCI_SETRECTANGULARSELECTIONCARET, mainSelCaretPos);
|
||||
_pEditView->execute(SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, rectSelCaretVirt);
|
||||
}
|
||||
else
|
||||
{
|
||||
_pEditView->execute(SCI_SETANCHOR, mainSelAnchor);
|
||||
_pEditView->execute(SCI_SETCURRENTPOS, mainSelCaretPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Notepad_plus::removeEmptyLine(bool isBlankContained)
|
||||
|
|
|
@ -66,7 +66,8 @@ enum WindowStatus { //bitwise mask
|
|||
enum trimOp {
|
||||
lineHeader = 0,
|
||||
lineTail = 1,
|
||||
lineEol = 2
|
||||
lineBoth = 2,
|
||||
lineEol = 3
|
||||
};
|
||||
|
||||
enum spaceTab {
|
||||
|
|
|
@ -1902,8 +1902,7 @@ void Notepad_plus::command(int id)
|
|||
std::lock_guard<std::mutex> lock(command_mutex);
|
||||
|
||||
_pEditView->execute(SCI_BEGINUNDOACTION);
|
||||
doTrim(lineTail);
|
||||
doTrim(lineHeader);
|
||||
doTrim(lineBoth);
|
||||
_pEditView->execute(SCI_ENDUNDOACTION);
|
||||
break;
|
||||
}
|
||||
|
@ -1920,8 +1919,7 @@ void Notepad_plus::command(int id)
|
|||
std::lock_guard<std::mutex> lock(command_mutex);
|
||||
|
||||
_pEditView->execute(SCI_BEGINUNDOACTION);
|
||||
doTrim(lineTail);
|
||||
doTrim(lineHeader);
|
||||
doTrim(lineBoth);
|
||||
_pEditView->execute(SCI_TARGETWHOLEDOCUMENT);
|
||||
_pEditView->execute(SCI_LINESJOIN);
|
||||
_pEditView->execute(SCI_ENDUNDOACTION);
|
||||
|
|
Loading…
Reference in New Issue