+ fix: Wrap to Column: respect tab width settings

This commit is contained in:
RaiKoHoff 2020-01-09 18:10:42 +01:00
parent c470b3aeb1
commit a8c66e7330
3 changed files with 25 additions and 31 deletions

View File

@ -4054,12 +4054,10 @@ void EditRemoveDuplicateLines(HWND hwnd, bool bRemoveEmptyLines)
//
// EditWrapToColumn()
//
void EditWrapToColumn(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
void EditWrapToColumn(HWND hwnd, DocPosU nColumn)
{
if (Sci_IsMultiOrRectangleSelection()) {
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SELRECTORMULTI);
return;
}
DocPosU const tabWidth = SciCall_GetTabWidth();
nColumn = clamppu(nColumn, tabWidth, LONG_LINES_MARKER_LIMIT);
DocPosU iCurPos = SciCall_GetCurrentPos();
DocPosU iAnchorPos = SciCall_GetAnchor();
@ -4105,6 +4103,7 @@ void EditWrapToColumn(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
#define ISWHITE(wc) (!(wc) || StrChrW(W_WHITESPACE,(wc)))
#define ISLINEBREAK(wc) (!(wc) || ((wc) == wszEOL[0]) || ((wc) == wszEOL[1]))
#define ISWORDCHAR(wc) (!ISWHITE(wc) && !ISLINEBREAK(wc) && !ISDELIMITER(wc))
#define ISTAB(wc) ((wc) == L'\t')
// --------------------------------------------------------------------------
DocPos iCaretShift = 0;
@ -4119,16 +4118,8 @@ void EditWrapToColumn(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
// read complete words
while (ISWORDCHAR(w) && (iTextW < cchTextW)) {
if (ISLINEBREAK(w)) {
if (w != L'\0') {
pszConvW[cchConvW++] = w;
}
iLineLength = 0;
}
else if (w != L'\0') {
pszConvW[cchConvW++] = w;
++iLineLength;
}
pszConvW[cchConvW++] = w;
++iLineLength;
w = pszTextW[++iTextW];
}
@ -4146,14 +4137,13 @@ void EditWrapToColumn(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
pszConvW[cchConvW++] = wszEOL[1];
}
if (cchConvW <= iCurPos) { iCaretShift += cchEOL; }
iLineLength = 0;
bModified = true;
pszConvW[cchConvW++] = w;
++iLineLength;
iLineLength = ISTAB(w) ? tabWidth : 1;
}
else {
pszConvW[cchConvW++] = w;
++iLineLength;
iLineLength += ISTAB(w) ? tabWidth : 1;
}
w = pszTextW[++iTextW];
}
@ -4162,23 +4152,22 @@ void EditWrapToColumn(HWND hwnd, DocPosU nColumn/*,int nTabWidth*/)
DocPosU iNextWordLen = 1;
DocPosU iNextW = iTextW;
WCHAR w2 = pszTextW[iNextW];
while (ISWORDCHAR(w2) && ((iLineLength + iNextWordLen) < nColumn) && (iNextW < cchTextW)) {
while (ISWORDCHAR(w2) && (iNextW < cchTextW)) {
w2 = pszTextW[++iNextW];
++iNextWordLen;
}
if ((iLineLength + iNextWordLen + 1) >= nColumn) {
pszConvW[cchConvW++] = wszEOL[0];
if (cchEOL > 1) {
pszConvW[cchConvW++] = wszEOL[1];
}
if (cchConvW <= iCurPos) { iCaretShift += cchEOL; }
iLineLength = 0;
bModified = true;
}
if (w != L'\0') {
if ((iLineLength + iNextWordLen) >= nColumn) {
pszConvW[cchConvW++] = wszEOL[0];
if (cchEOL > 1) {
pszConvW[cchConvW++] = wszEOL[1];
}
if (cchConvW <= iCurPos) { iCaretShift += cchEOL; }
iLineLength = 0;
bModified = true;
}
pszConvW[cchConvW++] = w;
++iLineLength;
iLineLength += ISTAB(w) ? tabWidth : 1;
}
}

View File

@ -134,6 +134,10 @@ inline DocPos clampp(DocPos x, DocPos lower, DocPos upper) {
return (x < lower) ? lower : ((x > upper) ? upper : x);
}
inline DocPosU clamppu(DocPosU x, DocPosU lower, DocPosU upper) {
return (x < lower) ? lower : ((x > upper) ? upper : x);
}
// Is the character an octal digit?
inline bool IsDigitA(const CHAR ch) { return ((ch >= '0') && (ch <= '9')); }
inline bool IsDigitW(const WCHAR wch) { return ((wch >= L'0') && (wch <= L'9')); }

View File

@ -4453,7 +4453,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
UINT uWrpCol = Globals.iWrapCol;
if (ColumnWrapDlg(hwnd, IDD_MUI_COLUMNWRAP, &uWrpCol))
{
Globals.iWrapCol = clampi((int)uWrpCol, 1, LONG_LINES_MARKER_LIMIT);
Globals.iWrapCol = clampi((int)uWrpCol, SciCall_GetTabWidth(), LONG_LINES_MARKER_LIMIT);
BeginWaitCursor(NULL);
EditWrapToColumn(Globals.hwndEdit, Globals.iWrapCol);
EndWaitCursor();
@ -5203,6 +5203,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
_iLongLinesLimit = clampi(_iLongLinesLimit, 0, LONG_LINES_MARKER_LIMIT);
Globals.fvCurFile.iLongLinesLimit = _iLongLinesLimit;
Settings.LongLinesLimit = _iLongLinesLimit;
Globals.iWrapCol = _iLongLinesLimit;
}
Settings.MarkLongLines = true;
Style_SetLongLineEdge(Globals.hwndEdit, Settings.LongLinesLimit);