mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ rfc: minor refactorings
This commit is contained in:
parent
f4253c9687
commit
989e39cdff
220
src/Edit.c
220
src/Edit.c
@ -1714,6 +1714,8 @@ void EditURLEncode()
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iCurPos = SciCall_GetCurrentPos();
|
||||
DocPos const iAnchorPos = SciCall_GetAnchor();
|
||||
DocPos const iSelSize = SciCall_GetSelText(NULL) - 1;
|
||||
@ -1744,9 +1746,6 @@ void EditURLEncode()
|
||||
ptrdiff_t const cchEscapedEnc = WideCharToMultiByte(Encoding_SciCP, 0, pszEscapedW, cchEscapedW,
|
||||
pszEscaped, (int)cchEscaped, NULL, NULL);
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (iCurPos < iAnchorPos) {
|
||||
@ -1756,8 +1755,6 @@ void EditURLEncode()
|
||||
}
|
||||
SciCall_ReplaceTarget(cchEscapedEnc, pszEscaped);
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
if (iCurPos < iAnchorPos) {
|
||||
EditSetSelectionEx(iCurPos + cchEscapedEnc, iCurPos, -1, -1);
|
||||
} else {
|
||||
@ -1766,6 +1763,8 @@ void EditURLEncode()
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
FreeMem(pszEscaped);
|
||||
FreeMem(pszEscapedW);
|
||||
}
|
||||
@ -1786,6 +1785,8 @@ void EditURLDecode()
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iCurPos = SciCall_GetCurrentPos();
|
||||
DocPos const iAnchorPos = SciCall_GetAnchor();
|
||||
DocPos const iSelSize = SciCall_GetSelText(NULL);
|
||||
@ -1819,9 +1820,6 @@ void EditURLDecode()
|
||||
int const cchUnescapedDec = WideCharToMultiByte(Encoding_SciCP, 0, pszUnescapedW, cchUnescapedW,
|
||||
pszUnescaped, (int)cchUnescaped, NULL, NULL);
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (iCurPos < iAnchorPos) {
|
||||
@ -1830,7 +1828,6 @@ void EditURLDecode()
|
||||
SciCall_SetTargetRange(iAnchorPos, iCurPos);
|
||||
}
|
||||
SciCall_ReplaceTarget(cchUnescapedDec, pszUnescaped);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
if (iCurPos < iAnchorPos) {
|
||||
EditSetSelectionEx(iCurPos + cchUnescapedDec, iCurPos, -1, -1);
|
||||
@ -1840,6 +1837,8 @@ void EditURLDecode()
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
FreeMem(pszTextW);
|
||||
FreeMem(pszUnescaped);
|
||||
FreeMem(pszUnescapedW);
|
||||
@ -2371,14 +2370,13 @@ void EditTabsToSpaces(int nTabWidth,bool bOnlyIndentingWS)
|
||||
iCurPos = iSelStart + cchConvM;
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_SAVE_TARGET_RANGE_;
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
SciCall_SetTargetRange(iSelStart, iSelEnd);
|
||||
SciCall_ReplaceTarget(cchConvM, pszText2);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
_END_UNDO_ACTION_;
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
FreeMem(pszText2);
|
||||
}
|
||||
FreeMem(pszConvW);
|
||||
@ -2400,6 +2398,8 @@ void EditSpacesToTabs(int nTabWidth,bool bOnlyIndentingWS)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos iCurPos = SciCall_GetCurrentPos();
|
||||
DocPos iAnchorPos = SciCall_GetAnchor();
|
||||
|
||||
@ -2486,16 +2486,16 @@ void EditSpacesToTabs(int nTabWidth,bool bOnlyIndentingWS)
|
||||
iCurPos = iSelStart + cchConvM;
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
SciCall_SetTargetRange(iSelStart, iSelEnd);
|
||||
SciCall_ReplaceTarget(cchConvM, pszText2);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
_END_UNDO_ACTION_;
|
||||
FreeMem(pszText2);
|
||||
}
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
FreeMem(pszConvW);
|
||||
}
|
||||
|
||||
@ -2626,7 +2626,9 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
return;
|
||||
}
|
||||
|
||||
char mszPrefix1[256 * 3] = { '\0' };
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
char mszPrefix1[256 * 3] = { '\0' };
|
||||
char mszAppend1[256 * 3] = { '\0' };
|
||||
|
||||
DocPos iSelStart = SciCall_GetSelectionStart();
|
||||
@ -2639,8 +2641,6 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
WideCharToMultiByteEx(Encoding_SciCP, 0, pwszAppend, -1, mszAppend1, COUNTOF(mszAppend1), NULL, NULL);
|
||||
}
|
||||
|
||||
DocLn iLine;
|
||||
|
||||
DocLn iLineStart = SciCall_LineFromPosition(iSelStart);
|
||||
DocLn iLineEnd = SciCall_LineFromPosition(iSelEnd);
|
||||
|
||||
@ -2815,11 +2815,7 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
for (iLine = iLineStart; iLine <= iLineEnd; iLine++) {
|
||||
DocPos iPos;
|
||||
for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine) {
|
||||
|
||||
if (StrIsNotEmpty(pwszPrefix)) {
|
||||
|
||||
@ -2835,7 +2831,7 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
StringCchCatA(mszInsert, COUNTOF(mszInsert), mszPrefix2);
|
||||
iPrefixNum++;
|
||||
}
|
||||
iPos = SciCall_PositionFromLine(iLine);
|
||||
DocPos const iPos = SciCall_PositionFromLine(iLine);
|
||||
SciCall_SetTargetRange(iPos, iPos);
|
||||
SciCall_ReplaceTarget(-1, mszInsert);
|
||||
}
|
||||
@ -2854,14 +2850,12 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
StringCchCatA(mszInsert, COUNTOF(mszInsert), mszAppend2);
|
||||
iAppendNum++;
|
||||
}
|
||||
iPos = SciCall_GetLineEndPosition(iLine);
|
||||
DocPos const iPos = SciCall_GetLineEndPosition(iLine);
|
||||
SciCall_SetTargetRange(iPos, iPos);
|
||||
SciCall_ReplaceTarget(-1, mszInsert);
|
||||
}
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
// extend selection to start of first line
|
||||
// the above code is not required when last line has been excluded
|
||||
if (iSelStart != iSelEnd) {
|
||||
@ -2879,6 +2873,8 @@ void EditModifyLines(LPCWSTR pwszPrefix, LPCWSTR pwszAppend)
|
||||
}
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -2979,6 +2975,8 @@ void EditIndentBlock(HWND hwnd, int cmd, bool bFormatIndentation, bool bForceAll
|
||||
//
|
||||
void EditAlignText(int nMode)
|
||||
{
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos iCurPos = SciCall_GetCurrentPos();
|
||||
DocPos iAnchorPos = SciCall_GetAnchor();
|
||||
|
||||
@ -3035,9 +3033,6 @@ void EditAlignText(int nMode)
|
||||
|
||||
if (chNewLineBuf && wchLineBuf && wchNewLineBuf) {
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
for (DocLn iLine = iLineStart; iLine <= iLineEnd; iLine++) {
|
||||
DocPos const iStartPos = SciCall_PositionFromLine(iLine);
|
||||
DocPos const iEndPos = SciCall_GetLineEndPosition(iLine);
|
||||
@ -3182,7 +3177,6 @@ void EditAlignText(int nMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
FreeMem(pWords);
|
||||
FreeMem(wchNewLineBuf);
|
||||
@ -3202,6 +3196,8 @@ void EditAlignText(int nMode)
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3217,13 +3213,14 @@ void EditEncloseSelection(LPCWSTR pwszOpen, LPCWSTR pwszClose)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
char mszOpen[256 * 3] = { '\0' };
|
||||
char mszClose[256 * 3] = { '\0' };
|
||||
|
||||
const DocPos iCurPos = SciCall_GetCurrentPos();
|
||||
const DocPos iAnchorPos = SciCall_GetAnchor();
|
||||
const DocPos iSelStart = SciCall_GetSelectionStart();
|
||||
const DocPos iSelEnd = SciCall_GetSelectionEnd();
|
||||
bool const bStraightSel = (SciCall_GetCurrentPos() >= SciCall_GetAnchor());
|
||||
DocPos const iSelStart = SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = SciCall_GetSelectionEnd();
|
||||
|
||||
if (StrIsNotEmpty(pwszOpen)) {
|
||||
WideCharToMultiByteEx(Encoding_SciCP, 0, pwszOpen, -1, mszOpen, COUNTOF(mszOpen), NULL, NULL);
|
||||
@ -3231,13 +3228,9 @@ void EditEncloseSelection(LPCWSTR pwszOpen, LPCWSTR pwszClose)
|
||||
if (StrIsNotEmpty(pwszClose)) {
|
||||
WideCharToMultiByteEx(Encoding_SciCP, 0, pwszClose, -1, mszClose, COUNTOF(mszClose), NULL, NULL);
|
||||
}
|
||||
|
||||
DocPos const iLenOpen = (DocPos)StringCchLenA(mszOpen, COUNTOF(mszOpen));
|
||||
DocPos const iLenClose = (DocPos)StringCchLenA(mszClose, COUNTOF(mszClose));
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (iLenOpen > 0) {
|
||||
@ -3250,12 +3243,17 @@ void EditEncloseSelection(LPCWSTR pwszOpen, LPCWSTR pwszClose)
|
||||
SciCall_ReplaceTarget(-1, mszClose);
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
// Fix selection
|
||||
EditSetSelectionEx(iAnchorPos + iLenOpen, iCurPos + iLenOpen, -1, -1);
|
||||
// Move selection
|
||||
SciCall_SetSelectionStart(iSelStart + iLenOpen);
|
||||
SciCall_SetSelectionEnd(iSelEnd + iLenOpen);
|
||||
if (!bStraightSel) {
|
||||
EditSetCaretToSelectionStart();
|
||||
}
|
||||
EditEnsureSelectionVisible();
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3272,8 +3270,7 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
return;
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
bool const bStraightSel = SciCall_GetAnchor() <= SciCall_GetCurrentPos();
|
||||
|
||||
@ -3407,15 +3404,14 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
|
||||
SciCall_SetSelectionStart(iSelStart + iSelStartOffset);
|
||||
SciCall_SetSelectionEnd(iSelEnd + iSelEndOffset);
|
||||
|
||||
if (!bStraightSel) {
|
||||
EditSetCaretToSelectionStart();
|
||||
}
|
||||
EditEnsureSelectionVisible();
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
EditEnsureSelectionVisible();
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3426,8 +3422,7 @@ void EditToggleLineCommentsSimple(HWND hwnd, LPCWSTR pwszComment, bool bInsertAt
|
||||
void EditToggleLineCommentsExtended(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iSelStart = Sci_GetSelectionStartEx();
|
||||
DocPos const iSelEnd = Sci_GetSelectionEndEx();
|
||||
@ -3544,9 +3539,9 @@ void EditToggleLineCommentsExtended(HWND hwnd, LPCWSTR pwszComment, bool bInsert
|
||||
}
|
||||
utarray_free(sel_positions);
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3571,6 +3566,8 @@ static DocPos _AppendSpaces(HWND hwnd, DocLn iLineStart, DocLn iLineEnd, DocPos
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
size_t size = (size_t)iMaxColumn;
|
||||
char* pmszPadStr = AllocMem(size + 1, HEAP_ZERO_MEMORY);
|
||||
FillMemory(pmszPadStr, size, ' ');
|
||||
@ -3579,9 +3576,6 @@ static DocPos _AppendSpaces(HWND hwnd, DocLn iLineStart, DocLn iLineEnd, DocPos
|
||||
|
||||
_IGNORE_NOTIFY_CHANGE_;
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
for (DocLn iLine = iLineStart; iLine <= iLineEnd; ++iLine) {
|
||||
|
||||
// insertion position is at end of line
|
||||
@ -3606,10 +3600,10 @@ static DocPos _AppendSpaces(HWND hwnd, DocLn iLineStart, DocLn iLineEnd, DocPos
|
||||
spcCount += iPadLen;
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_OBSERVE_NOTIFY_CHANGE_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
FreeMem(pmszPadStr);
|
||||
|
||||
return spcCount;
|
||||
@ -3744,14 +3738,13 @@ void EditStripFirstCharacter(HWND hwnd)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iSelStart = SciCall_IsSelectionEmpty() ? 0 : SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = SciCall_IsSelectionEmpty() ? Sci_GetDocEndPosition() : SciCall_GetSelectionEnd();
|
||||
DocLn const iLineStart = SciCall_LineFromPosition(iSelStart);
|
||||
DocLn const iLineEnd = SciCall_LineFromPosition(iSelEnd);
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (SciCall_IsSelectionRectangle()) {
|
||||
@ -3804,9 +3797,9 @@ void EditStripFirstCharacter(HWND hwnd)
|
||||
}
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3822,14 +3815,13 @@ void EditStripLastCharacter(HWND hwnd, bool bIgnoreSelection, bool bTrailingBlan
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iSelStart = (SciCall_IsSelectionEmpty() || bIgnoreSelection) ? 0 : SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = (SciCall_IsSelectionEmpty() || bIgnoreSelection) ? Sci_GetDocEndPosition() : SciCall_GetSelectionEnd();
|
||||
DocLn const iLineStart = SciCall_LineFromPosition(iSelStart);
|
||||
DocLn const iLineEnd = SciCall_LineFromPosition(iSelEnd);
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (Sci_IsMultiOrRectangleSelection() && !bIgnoreSelection) {
|
||||
@ -3922,9 +3914,9 @@ void EditStripLastCharacter(HWND hwnd, bool bIgnoreSelection, bool bTrailingBlan
|
||||
}
|
||||
}
|
||||
}
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -3934,6 +3926,8 @@ void EditStripLastCharacter(HWND hwnd, bool bIgnoreSelection, bool bTrailingBlan
|
||||
//
|
||||
void EditCompressBlanks()
|
||||
{
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
const bool bIsSelEmpty = SciCall_IsSelectionEmpty();
|
||||
|
||||
const DocPos iSelStartPos = SciCall_GetSelectionStart();
|
||||
@ -4069,9 +4063,6 @@ void EditCompressBlanks()
|
||||
|
||||
if (bModified) {
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
if (!SciCall_IsSelectionEmpty()) {
|
||||
@ -4081,8 +4072,6 @@ void EditCompressBlanks()
|
||||
}
|
||||
SciCall_ReplaceTarget(-1, pszOut);
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
DocPos const iNewLen = (DocPos)StringCchLenA(pszOut, SizeOfMem(pszOut));
|
||||
|
||||
if (iCurPos < iAnchorPos) {
|
||||
@ -4102,6 +4091,8 @@ void EditCompressBlanks()
|
||||
}
|
||||
FreeMem(pszOut);
|
||||
}
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4131,8 +4122,7 @@ void EditRemoveBlankLines(HWND hwnd, bool bMerge, bool bRemoveWhiteSpace)
|
||||
--iEndLine;
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
@ -4181,8 +4171,7 @@ void EditRemoveBlankLines(HWND hwnd, bool bMerge, bool bRemoveWhiteSpace)
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4199,6 +4188,8 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iSelStart = SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = SciCall_GetSelectionEnd();
|
||||
|
||||
@ -4221,9 +4212,6 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines)
|
||||
return;
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
for (DocLn iCurLine = iStartLine; iCurLine < iEndLine; ++iCurLine) {
|
||||
@ -4254,9 +4242,9 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines)
|
||||
} // empty
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4374,6 +4362,8 @@ void EditFocusMarkedLinesCmd(HWND hwnd, bool bCopy, bool bDelete)
|
||||
//
|
||||
void EditWrapToColumn(DocPosU nColumn)
|
||||
{
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPosU const tabWidth = SciCall_GetTabWidth();
|
||||
nColumn = clamppu(nColumn, tabWidth, LONG_LINES_MARKER_LIMIT);
|
||||
|
||||
@ -4508,17 +4498,16 @@ void EditWrapToColumn(DocPosU nColumn)
|
||||
}
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
SciCall_SetTargetRange(iSelStart, iSelEnd);
|
||||
SciCall_ReplaceTarget(cchConvM, pszText);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
_END_UNDO_ACTION_;
|
||||
FreeMem(pszText);
|
||||
}
|
||||
}
|
||||
FreeMem(pszConvW);
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4536,6 +4525,8 @@ void EditWrapToColumnForce(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
size_t const size = (size_t)nColumn + 1LL;
|
||||
char const spc = ' ';
|
||||
char* const pTxt = (char* const)AllocMem(size + 1, HEAP_ZERO_MEMORY);
|
||||
@ -4543,9 +4534,6 @@ void EditWrapToColumnForce(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
|
||||
int const width_pix = SciCall_TextWidth(STYLE_DEFAULT, pTxt);
|
||||
FreeMem(pTxt);
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
if (SciCall_IsSelectionEmpty()) {
|
||||
SciCall_TargetWholeDocument();
|
||||
@ -4553,8 +4541,8 @@ void EditWrapToColumnForce(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
|
||||
SciCall_TargetFromSelection();
|
||||
}
|
||||
SciCall_LinesSplit(width_pix);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
_END_UNDO_ACTION_;
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -4566,14 +4554,12 @@ void EditWrapToColumnForce(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
|
||||
void EditSplitLines(HWND hwnd)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
SciCall_TargetFromSelection();
|
||||
SciCall_LinesSplit(0);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
_END_UNDO_ACTION_;
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4596,6 +4582,8 @@ void EditJoinLinesEx(bool bPreserveParagraphs, bool bCRLF2Space)
|
||||
return;
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
DocPos const iSelStart = SciCall_GetSelectionStart();
|
||||
DocPos const iSelEnd = SciCall_GetSelectionEnd();
|
||||
DocPos const iSelLength = (iSelEnd - iSelStart);
|
||||
@ -4649,15 +4637,13 @@ void EditJoinLinesEx(bool bPreserveParagraphs, bool bCRLF2Space)
|
||||
}
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
SciCall_SetTargetRange(iSelStart, iSelEnd);
|
||||
SciCall_ReplaceTarget(cchJoin, pszJoin);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
_END_UNDO_ACTION_;
|
||||
}
|
||||
FreeMem(pszJoin);
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -4767,6 +4753,8 @@ void EditSortLines(HWND hwnd, int iSortFlags)
|
||||
return; // no selection
|
||||
}
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
bool const bIsMultiSel = Sci_IsMultiOrRectangleSelection();
|
||||
|
||||
DocPos const iSelStart = SciCall_GetSelectionStart(); //iSelStart = SciCall_PositionFromLine(iLine);
|
||||
@ -4970,24 +4958,18 @@ void EditSortLines(HWND hwnd, int iSortFlags)
|
||||
}
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
//SciCall_SetTargetRange(SciCall_PositionFromLine(iLineStart), SciCall_PositionFromLine(iLineEnd + 1));
|
||||
SciCall_SetTargetRange(SciCall_PositionFromLine(iLineStart), SciCall_GetLineEndPosition(iLineEnd));
|
||||
SciCall_ReplaceTarget(-1, pmszResult);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
FreeMem(pmszResult);
|
||||
|
||||
if (bIsMultiSel) {
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, iAnchorPosVS, iCurPosVS);
|
||||
} else {
|
||||
EditSetSelectionEx(iAnchorPos, iCurPos, -1, -1);
|
||||
}
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
|
||||
|
||||
@ -5505,13 +5487,14 @@ static DocPos _FindInTarget(LPCSTR szFind, DocPos length, int sFlags,
|
||||
return iPos;
|
||||
}
|
||||
|
||||
// remember original target range
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
DocPos start = *begin;
|
||||
DocPos stop = *end;
|
||||
bool const bFindNext = (start <= stop); // else find previous
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
SciCall_SetSearchFlags(sFlags);
|
||||
SciCall_SetTargetRange(start, stop);
|
||||
iPos = SciCall_SearchInTarget(length, szFind);
|
||||
@ -5544,7 +5527,7 @@ static DocPos _FindInTarget(LPCSTR szFind, DocPos length, int sFlags,
|
||||
}
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); // restore original target range
|
||||
|
||||
return iPos;
|
||||
}
|
||||
@ -6847,8 +6830,8 @@ void EditMarkAllOccurrences(HWND hwnd, bool bForceClear)
|
||||
void EditSelectionMultiSelectAll()
|
||||
{
|
||||
if (SciCall_GetSelText(NULL) > 1) {
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
SciCall_TargetWholeDocument();
|
||||
|
||||
@ -6860,10 +6843,9 @@ void EditSelectionMultiSelectAll()
|
||||
if (SciCall_GetSelectionNAnchor(0) > SciCall_GetSelectionNCaret(0)) {
|
||||
SciCall_SwapMainAnchorCaret();
|
||||
}
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
|
||||
EditEnsureSelectionVisible();
|
||||
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6959,21 +6941,19 @@ bool EditReplace(HWND hwnd, LPEDITFINDREPLACE lpefr)
|
||||
return EditFindNext(hwnd, lpefr, false, false);
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
_SAVE_TARGET_RANGE_;
|
||||
|
||||
_BEGIN_UNDO_ACTION_;
|
||||
|
||||
SciCall_TargetFromSelection();
|
||||
Sci_ReplaceTarget(iReplaceMsg, -1, pszReplace);
|
||||
// move caret behind replacement
|
||||
SciCall_SetCurrentPos(SciCall_GetTargetEnd());
|
||||
Globals.iReplacedOccurrences = 1;
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
_END_UNDO_ACTION_;
|
||||
FreeMem(pszReplace);
|
||||
|
||||
_END_UNDO_ACTION_;
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
return EditFindNext(hwnd, lpefr, false, false);
|
||||
}
|
||||
@ -7007,10 +6987,10 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos,
|
||||
return -1; // recoding of clipboard canceled
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
DocPos const _saveTargetBeg_ = SciCall_GetTargetStart();
|
||||
DocPos const _saveTargetEnd_ = SciCall_GetTargetEnd();
|
||||
|
||||
DocPos start = iStartPos;
|
||||
DocPos start = iStartPos;
|
||||
DocPos end = iEndPos;
|
||||
DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_NORM);
|
||||
|
||||
@ -7034,7 +7014,7 @@ int EditReplaceAllInRange(HWND hwnd, LPEDITFINDREPLACE lpefr, DocPos iStartPos,
|
||||
_END_UNDO_ACTION_;
|
||||
|
||||
*enlargement = (iEndPos - iOrigEndPos);
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd + *enlargement); //restore
|
||||
SciCall_SetTargetRange(_saveTargetBeg_, _saveTargetEnd_ + *enlargement); //restore
|
||||
return iCount;
|
||||
}
|
||||
|
||||
|
||||
@ -133,6 +133,13 @@ void EditDeleteMarkerInSelection();
|
||||
void EditSelectionMultiSelectAll();
|
||||
void EditSelectionMultiSelectAllEx(CLPCEDITFINDREPLACE edFndRpl);
|
||||
|
||||
// maybe removed beyond next release
|
||||
#define _SAVE_TARGET_RANGE_ DocPos const _saveTargetBeg_ = SciCall_GetTargetStart();\
|
||||
DocPos const _saveTargetEnd_ = SciCall_GetTargetEnd()
|
||||
#define _RESTORE_TARGET_RANGE_ SciCall_SetTargetRange(_saveTargetBeg_, _saveTargetEnd_)
|
||||
//#define _SAVE_TARGET_RANGE_
|
||||
//#define _RESTORE_TARGET_RANGE_
|
||||
|
||||
//
|
||||
// Folding Functions
|
||||
//
|
||||
|
||||
@ -7228,13 +7228,10 @@ void HandleColorDefClicked(HWND hwnd, const DocPos position)
|
||||
(int)GetRValue(rgbNew), (int)GetGValue(rgbNew), (int)GetBValue(rgbNew));
|
||||
}
|
||||
|
||||
DocPos const saveTargetBeg = SciCall_GetTargetStart();
|
||||
DocPos const saveTargetEnd = SciCall_GetTargetEnd();
|
||||
|
||||
_SAVE_TARGET_RANGE_;
|
||||
SciCall_SetTargetRange(firstPos, lastPos);
|
||||
SciCall_ReplaceTarget(length, wchColor);
|
||||
|
||||
SciCall_SetTargetRange(saveTargetBeg, saveTargetEnd); //restore
|
||||
_RESTORE_TARGET_RANGE_;
|
||||
|
||||
EditUpdateVisibleIndicators();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user