Add support selection for "EOL to Space" commands
And rename "Remove Unnecessary Blank and EOL" command to "Trim both and EOL to Space". Fix #12702, close #12711
This commit is contained in:
parent
3ee8660c23
commit
81a77f13a6
|
@ -158,7 +158,7 @@ The comments are here for explanation, it's not necessary to translate them.
|
|||
<Item id="42042" name="Trim Leading Space"/>
|
||||
<Item id="42043" name="Trim Leading and Trailing Space"/>
|
||||
<Item id="42044" name="EOL to Space"/>
|
||||
<Item id="42045" name="Remove Unnecessary Blank and EOL"/>
|
||||
<Item id="42045" name="Trim both and EOL to Space"/>
|
||||
<Item id="42046" name="TAB to Space"/>
|
||||
<Item id="42054" name="Space to TAB (All)"/>
|
||||
<Item id="42053" name="Space to TAB (Leading)"/>
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
<Item id="42042" name="Trim Leading Space"/>
|
||||
<Item id="42043" name="Trim Leading and Trailing Space"/>
|
||||
<Item id="42044" name="EOL to Space"/>
|
||||
<Item id="42045" name="Remove Unnecessary Blank and EOL"/>
|
||||
<Item id="42045" name="Trim both and EOL to Space"/>
|
||||
<Item id="42046" name="TAB to Space"/>
|
||||
<Item id="42054" name="Space to TAB (All)"/>
|
||||
<Item id="42053" name="Space to TAB (Leading)"/>
|
||||
|
|
|
@ -1493,11 +1493,13 @@ void Notepad_plus::doTrim(trimOp whichPart)
|
|||
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);
|
||||
bool isEntireDoc = (mainSelAnchor == mainSelCaretPos);
|
||||
auto docLength = _pEditView->execute(SCI_GETLENGTH);
|
||||
|
||||
// block selection is not supported
|
||||
if ((_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN))
|
||||
return;
|
||||
|
||||
// auto-expand of partially selected lines
|
||||
if (!isEntireDoc)
|
||||
{
|
||||
|
@ -1516,22 +1518,25 @@ void Notepad_plus::doTrim(trimOp whichPart)
|
|||
_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::eol2ws()
|
||||
{
|
||||
bool isEntireDoc = (_pEditView->execute(SCI_GETANCHOR) == _pEditView->execute(SCI_GETCURRENTPOS));
|
||||
|
||||
// block selection is not supported
|
||||
if ((_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) || (_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN))
|
||||
return;
|
||||
|
||||
_pEditView->execute(isEntireDoc ? SCI_TARGETWHOLEDOCUMENT: SCI_TARGETFROMSELECTION);
|
||||
_pEditView->execute(SCI_LINESJOIN);
|
||||
}
|
||||
|
||||
void Notepad_plus::removeEmptyLine(bool isBlankContained)
|
||||
|
|
|
@ -599,6 +599,7 @@ private:
|
|||
|
||||
void wsTabConvert(spaceTab whichWay);
|
||||
void doTrim(trimOp whichPart);
|
||||
void eol2ws();
|
||||
void removeEmptyLine(bool isBlankContained);
|
||||
void removeDuplicateLines();
|
||||
void launchAnsiCharPanel();
|
||||
|
|
|
@ -524,7 +524,7 @@ BEGIN
|
|||
MENUITEM "Trim Leading Space", IDM_EDIT_TRIMLINEHEAD
|
||||
MENUITEM "Trim Leading and Trailing Space", IDM_EDIT_TRIM_BOTH
|
||||
MENUITEM "EOL to Space", IDM_EDIT_EOL2WS
|
||||
MENUITEM "Remove Unnecessary Blank and EOL", IDM_EDIT_TRIMALL
|
||||
MENUITEM "Trim both and EOL to Space", IDM_EDIT_TRIMALL
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "TAB to Space", IDM_EDIT_TAB2SW
|
||||
MENUITEM "Space to TAB (All)", IDM_EDIT_SW2TAB_ALL
|
||||
|
|
|
@ -1909,8 +1909,7 @@ void Notepad_plus::command(int id)
|
|||
|
||||
case IDM_EDIT_EOL2WS:
|
||||
_pEditView->execute(SCI_BEGINUNDOACTION);
|
||||
_pEditView->execute(SCI_TARGETWHOLEDOCUMENT);
|
||||
_pEditView->execute(SCI_LINESJOIN);
|
||||
eol2ws();
|
||||
_pEditView->execute(SCI_ENDUNDOACTION);
|
||||
break;
|
||||
|
||||
|
@ -1919,9 +1918,10 @@ void Notepad_plus::command(int id)
|
|||
std::lock_guard<std::mutex> lock(command_mutex);
|
||||
|
||||
_pEditView->execute(SCI_BEGINUNDOACTION);
|
||||
bool isEntireDoc = _pEditView->execute(SCI_GETANCHOR) == _pEditView->execute(SCI_GETCURRENTPOS);
|
||||
doTrim(lineBoth);
|
||||
_pEditView->execute(SCI_TARGETWHOLEDOCUMENT);
|
||||
_pEditView->execute(SCI_LINESJOIN);
|
||||
if (isEntireDoc || _pEditView->execute(SCI_GETANCHOR) != _pEditView->execute(SCI_GETCURRENTPOS))
|
||||
eol2ws();
|
||||
_pEditView->execute(SCI_ENDUNDOACTION);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue