Révision | 28691 (tree) |
---|---|
l'heure | 2019-11-08 04:18:01 |
Auteur | stefankueng |
improve detecting of space/tabs to use.
@@ -6186,6 +6186,23 @@ | ||
6186 | 6186 | UseViewBlock(pwndView, 0, GetViewCount() - 1, fn); |
6187 | 6187 | } |
6188 | 6188 | |
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 | + | |
6189 | 6206 | int CBaseView::GetIndentCharsForLine(int x, int y) |
6190 | 6207 | { |
6191 | 6208 | const int maxGuessLine = 100; |
@@ -6197,36 +6214,33 @@ | ||
6197 | 6214 | // we can not test for spaces, since even if tabs are used, |
6198 | 6215 | // spaces are used in a tabified file for alignment. |
6199 | 6216 | 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 | |
6203 | 6220 | |
6204 | - if (m_nTabMode & TABMODE_SMARTINDENT) | |
6221 | + // detect lines nearby | |
6222 | + for (int i = y - 1, j = y + 1; nTabMode == -1; --i, ++j) | |
6205 | 6223 | { |
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)) | |
6208 | 6235 | { |
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; | |
6229 | 6238 | } |
6239 | + else if ((GetLargestSpaceStreak(ac) > m_nTabSize) && (GetLargestSpaceStreak(bc) > m_nTabSize)) | |
6240 | + { | |
6241 | + nTabMode = 1; | |
6242 | + break; | |
6243 | + } | |
6230 | 6244 | } |
6231 | 6245 | } |
6232 | 6246 | else |
@@ -1,6 +1,6 @@ | ||
1 | 1 | // TortoiseMerge - a Diff/Patch program |
2 | 2 | |
3 | -// Copyright (C) 2003-2015, 2017-2018 - TortoiseSVN | |
3 | +// Copyright (C) 2003-2015, 2017-2019 - TortoiseSVN | |
4 | 4 | |
5 | 5 | // This program is free software; you can redistribute it and/or |
6 | 6 | // modify it under the terms of the GNU General Public License |
@@ -218,6 +218,7 @@ | ||
218 | 218 | static bool IsViewGood(const CBaseView* view ) { return (view != 0) && view->IsWindowVisible(); } |
219 | 219 | static CBaseView * GetFirstGoodView(); |
220 | 220 | |
221 | + int GetLargestSpaceStreak(const CString& line); | |
221 | 222 | int GetIndentCharsForLine(int x, int y); |
222 | 223 | void AddIndentationForSelectedBlock(); |
223 | 224 | void RemoveIndentationForSelectedBlock(); |