Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
bf228912
Commit
bf228912
authored
Oct 31, 2009
by
Roopesh Chander
Committed by
Thorbjørn Lindeijer
Feb 08, 2010
Browse files
Look both forward and backward for auto-determining spaces vs tabs
parent
9822fb65
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/texteditor/behaviorsettingspage.ui
View file @
bf228912
...
...
@@ -50,10 +50,10 @@
<bool>
false
</bool>
</property>
<property
name=
"toolTip"
>
<string>
Automatically determine
whether to insert spaces or tabs based on th
e previous line
in the file
</string>
<string>
Automatically determine
based on the nearest indented lin
e
(
previous line
preferred over next line)
</string>
</property>
<property
name=
"text"
>
<string>
Based on the
previous
line
</string>
<string>
Based on the
surrounding
line
s
</string>
</property>
</widget>
</item>
...
...
src/plugins/texteditor/tabsettings.cpp
View file @
bf228912
...
...
@@ -231,19 +231,26 @@ int TabSettings::indentedColumn(int column, bool doIndent) const
bool
TabSettings
::
guessSpacesForTabs
(
const
QTextBlock
&
_block
)
const
{
if
(
m_autoSpacesForTabs
&&
_block
.
isValid
())
{
QTextBlock
block
=
_block
;
const
QTextDocument
*
doc
=
block
.
document
();
int
maxLookBack
=
100
;
while
(
block
.
isValid
()
&&
block
!=
doc
->
begin
()
&&
maxLookBack
--
>
0
)
{
block
=
block
.
previous
();
if
(
block
.
text
().
isEmpty
())
continue
;
QChar
firstChar
=
block
.
text
().
at
(
0
);
if
(
firstChar
==
QLatin1Char
(
' '
))
{
return
true
;
}
else
if
(
firstChar
==
QLatin1Char
(
'\t'
))
{
return
false
;
QVector
<
QTextBlock
>
currentBlocks
(
2
,
_block
);
// [0] looks back; [1] looks forward
int
maxLookAround
=
100
;
while
(
maxLookAround
--
>
0
)
{
currentBlocks
[
0
]
=
currentBlocks
.
at
(
0
).
previous
();
currentBlocks
[
1
]
=
currentBlocks
.
at
(
1
).
next
();
bool
done
=
true
;
foreach
(
QTextBlock
block
,
currentBlocks
)
{
if
(
block
.
isValid
())
done
=
false
;
if
(
!
block
.
isValid
()
||
block
.
text
().
isEmpty
())
continue
;
QChar
firstChar
=
block
.
text
().
at
(
0
);
if
(
firstChar
==
QLatin1Char
(
' '
))
{
return
true
;
}
else
if
(
firstChar
==
QLatin1Char
(
'\t'
))
{
return
false
;
}
}
if
(
done
)
break
;
}
}
return
m_spacesForTabs
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment