• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision28691 (tree)
Time2019-11-08 04:18:01
Authorstefankueng

Log Message

improve detecting of space/tabs to use.

Change Summary

Incremental Difference

--- trunk/src/TortoiseMerge/BaseView.cpp (revision 28690)
+++ trunk/src/TortoiseMerge/BaseView.cpp (revision 28691)
@@ -6186,6 +6186,23 @@
61866186 UseViewBlock(pwndView, 0, GetViewCount() - 1, fn);
61876187 }
61886188
6189+int CBaseView::GetLargestSpaceStreak(const CString& line)
6190+{
6191+ int count = 0;
6192+ int maxstreak = 0;
6193+ for (int i = 0; i < line.GetLength(); ++i)
6194+ {
6195+ if (line[i] == ' ')
6196+ ++count;
6197+ else
6198+ {
6199+ maxstreak = std::max(count, maxstreak);
6200+ count = 0;
6201+ }
6202+ }
6203+ return std::max(count, maxstreak);
6204+}
6205+
61896206 int CBaseView::GetIndentCharsForLine(int x, int y)
61906207 {
61916208 const int maxGuessLine = 100;
@@ -6197,36 +6214,33 @@
61976214 // we can not test for spaces, since even if tabs are used,
61986215 // spaces are used in a tabified file for alignment.
61996216 if (line.Find('\t') >= 0)
6200- nTabMode = 0; // use tabs
6201- else if (line.GetLength() > m_nTabSize)
6202- nTabMode = 1; // use spaces
6217+ nTabMode = 0; // use tabs
6218+ else if (GetLargestSpaceStreak(line) > m_nTabSize)
6219+ nTabMode = 1; // use spaces
62036220
6204- if (m_nTabMode & TABMODE_SMARTINDENT)
6221+ // detect lines nearby
6222+ for (int i = y - 1, j = y + 1; nTabMode == -1; --i, ++j)
62056223 {
6206- // detect lines nearby
6207- for (int i = y - 1, j = y + 1; nTabMode == -1; --i, ++j)
6224+ bool above = i >= 0 && i >= y - maxGuessLine;
6225+ bool below = j < GetViewCount() && j <= y + maxGuessLine;
6226+ if (!(above || below))
6227+ break;
6228+ auto ac = CString();
6229+ auto bc = CString();
6230+ if (above)
6231+ ac = GetViewLine(i);
6232+ if (below)
6233+ bc = GetViewLine(j);
6234+ if ((ac.Find('\t') >= 0) || (bc.Find('\t') >= 0))
62086235 {
6209- bool above = i > 0 && i >= y - maxGuessLine;
6210- bool below = j < GetViewCount() && j <= y + maxGuessLine;
6211- if (!(above || below))
6212- break;
6213- auto ac = CString();
6214- auto bc = CString();
6215- if (above)
6216- ac = GetViewLine(i);
6217- if (below)
6218- bc = GetViewLine(j);
6219- if ((ac.Find('\t') >= 0) || (bc.Find('\t') >= 0))
6220- {
6221- nTabMode = 0;
6222- break;
6223- }
6224- else if ((ac.GetLength() > m_nTabSize) && (bc.GetLength() > m_nTabSize))
6225- {
6226- nTabMode = 1;
6227- break;
6228- }
6236+ nTabMode = 0;
6237+ break;
62296238 }
6239+ else if ((GetLargestSpaceStreak(ac) > m_nTabSize) && (GetLargestSpaceStreak(bc) > m_nTabSize))
6240+ {
6241+ nTabMode = 1;
6242+ break;
6243+ }
62306244 }
62316245 }
62326246 else
--- trunk/src/TortoiseMerge/BaseView.h (revision 28690)
+++ trunk/src/TortoiseMerge/BaseView.h (revision 28691)
@@ -1,6 +1,6 @@
11 // TortoiseMerge - a Diff/Patch program
22
3-// Copyright (C) 2003-2015, 2017-2018 - TortoiseSVN
3+// Copyright (C) 2003-2015, 2017-2019 - TortoiseSVN
44
55 // This program is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU General Public License
@@ -218,6 +218,7 @@
218218 static bool IsViewGood(const CBaseView* view ) { return (view != 0) && view->IsWindowVisible(); }
219219 static CBaseView * GetFirstGoodView();
220220
221+ int GetLargestSpaceStreak(const CString& line);
221222 int GetIndentCharsForLine(int x, int y);
222223 void AddIndentationForSelectedBlock();
223224 void RemoveIndentationForSelectedBlock();
Show on old repository browser