From bfe07dba671a854e9239dc2b817d88a570bc1ba1 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 23 Mar 2018 16:27:23 +0100 Subject: [PATCH] + fix: "Remove Duplicate Lines": skipping line on progress to next compare when removing previous duplicate --- src/Edit.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index bf1f86cd6..650ca5b70 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -3596,7 +3596,6 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines) DocLn iStartLine = 0; DocLn iEndLine = 0; - const DocLn iLastLine = SciCall_GetLineCount() - 1; const DocPos iSelStart = SciCall_GetSelectionStart(); const DocPos iSelEnd = SciCall_GetSelectionEnd(); @@ -3608,7 +3607,7 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines) if (iSelEnd <= SciCall_PositionFromLine(iEndLine)) { --iEndLine; } } else { - iEndLine = iLastLine; + iEndLine = SciCall_GetLineCount() - 1; // last line } if ((iEndLine - iStartLine) <= 1) { return; } @@ -3631,29 +3630,34 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines) { const DocPos iCurLnLen = SciCall_GetLine(iCurLine, pCurrentLine); - if (!bRemoveEmptyLines && (iCurLnLen <= iEmptyLnLen)) { continue; } + if (bRemoveEmptyLines || (iCurLnLen > iEmptyLnLen)) { - for (DocLn iCompareLine = iCurLine + 1; iCompareLine < iEndLine; ++iCompareLine) - { - const DocPos iCmpLnLen = SciCall_GetLine(iCompareLine, NULL); - - if (!bRemoveEmptyLines && (iCmpLnLen <= iEmptyLnLen)) { continue; } + for (DocLn iCompareLine = iCurLine + 1; iCompareLine < iEndLine; ++iCompareLine) + { + const DocPos iCmpLnLen = SciCall_GetLine(iCompareLine, NULL); - const DocPos iBegCmpLine = SciCall_PositionFromLine(iCompareLine); - const char* pCompareLine = SciCall_GetRangePointer(iBegCmpLine, iCmpLnLen); + if (bRemoveEmptyLines || (iCmpLnLen > iEmptyLnLen)) { - if (iCurLnLen == iCmpLnLen) { - if (StringCchCompareNA(pCurrentLine, iCurLnLen, pCompareLine, iCmpLnLen) == 0) { - SciCall_SetTargetRange(iBegCmpLine, iBegCmpLine + iCmpLnLen); - SciCall_ReplaceTarget(0, ""); - --iEndLine; - } + const DocPos iBegCmpLine = SciCall_PositionFromLine(iCompareLine); + const char* pCompareLine = SciCall_GetRangePointer(iBegCmpLine, iCmpLnLen + 2); + + if (iCurLnLen == iCmpLnLen) { + if (StringCchCompareNA(pCurrentLine, iCurLnLen, pCompareLine, iCmpLnLen) == 0) { + SciCall_SetTargetRange(iBegCmpLine, iBegCmpLine + iCmpLnLen); + SciCall_ReplaceTarget(0, ""); + --iCompareLine; // proactive preventing progress to avoid comparison line skip + --iEndLine; + } + } + } // empty } - } + } // empty } - FreeMem(pCurrentLine); + EditLeaveTargetTransaction(); ObserveNotifyChangeEvent(); + + FreeMem(pCurrentLine); }