Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
6a12c99b
Commit
6a12c99b
authored
15 years ago
by
Christian Kamm
Browse files
Options
Downloads
Patches
Plain Diff
QmlJSEditor: Improve indentation of square brackets.
Task-number: QTCREATORBUG-583 Reviewed-by: Roberto Raggi
parent
3d853792
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/qmljs/qmljsindenter.cpp
+36
-9
36 additions, 9 deletions
src/libs/qmljs/qmljsindenter.cpp
src/libs/qmljs/qmljsindenter.h
+1
-0
1 addition, 0 deletions
src/libs/qmljs/qmljsindenter.h
with
37 additions
and
9 deletions
src/libs/qmljs/qmljsindenter.cpp
+
36
−
9
View file @
6a12c99b
...
...
@@ -253,12 +253,14 @@ QString QmlJSIndenter::trimmedCodeLine(const QString &t)
switch
(
last
.
kind
)
{
case
Token
::
LeftParenthesis
:
case
Token
::
LeftBrace
:
case
Token
::
LeftBracket
:
case
Token
::
Semicolon
:
case
Token
::
Delimiter
:
break
;
case
Token
::
RightParenthesis
:
case
Token
::
RightBrace
:
case
Token
::
RightBracket
:
if
(
isBinding
)
needSemicolon
=
true
;
break
;
...
...
@@ -267,8 +269,6 @@ QString QmlJSIndenter::trimmedCodeLine(const QString &t)
case
Token
::
Number
:
case
Token
::
Colon
:
case
Token
::
Comma
:
case
Token
::
LeftBracket
:
case
Token
::
RightBracket
:
needSemicolon
=
true
;
break
;
...
...
@@ -314,6 +314,31 @@ QChar QmlJSIndenter::lastParen() const
return
QChar
();
}
bool
QmlJSIndenter
::
hasUnclosedParenOrBracket
()
const
{
int
closedParen
=
0
;
int
closedBracket
=
0
;
for
(
int
index
=
yyLinizerState
.
tokens
.
size
()
-
1
;
index
!=
-
1
;
--
index
)
{
const
Token
&
token
=
yyLinizerState
.
tokens
.
at
(
index
);
if
(
token
.
is
(
Token
::
RightParenthesis
))
{
closedParen
++
;
}
else
if
(
token
.
is
(
Token
::
RightBracket
))
{
closedBracket
++
;
}
else
if
(
token
.
is
(
Token
::
LeftParenthesis
))
{
closedParen
--
;
if
(
closedParen
<
0
)
return
true
;
}
else
if
(
token
.
is
(
Token
::
LeftBracket
))
{
closedBracket
--
;
if
(
closedBracket
<
0
)
return
true
;
}
}
return
false
;
}
/*
Returns true if typedIn the same as okayCh or is null; otherwise
returns false.
...
...
@@ -383,8 +408,8 @@ bool QmlJSIndenter::readLine()
the other way around, as we are parsing backwards.
*/
yyLinizerState
.
braceDepth
+=
yyLinizerState
.
line
.
count
(
'}'
)
-
yyLinizerState
.
line
.
count
(
'{'
);
yyLinizerState
.
line
.
count
(
'}'
)
+
yyLinizerState
.
line
.
count
(
']'
)
-
yyLinizerState
.
line
.
count
(
'{'
)
-
yyLinizerState
.
line
.
count
(
'['
)
;
/*
We use a dirty trick for
...
...
@@ -620,7 +645,7 @@ bool QmlJSIndenter::isUnfinishedLine()
const
QChar
lastCh
=
yyLine
->
at
(
yyLine
->
length
()
-
1
);
if
(
QString
::
fromLatin1
(
"{};"
).
indexOf
(
lastCh
)
==
-
1
)
{
if
(
QString
::
fromLatin1
(
"{};
[]
"
).
indexOf
(
lastCh
)
==
-
1
)
{
/*
It doesn't end with ';' or similar. If it's not an "if (x)", it must be an unfinished line.
*/
...
...
@@ -630,15 +655,16 @@ bool QmlJSIndenter::isUnfinishedLine()
unf
=
false
;
}
else
if
(
lastCh
==
QLatin1Char
(
';'
))
{
if
(
lastParen
()
==
QLatin1Char
(
'('
))
{
if
(
hasUnclosedParenOrBracket
(
))
{
/*
Exception:
for (int i = 1; i < 10;
*/
unf
=
true
;
}
else
if
(
readLine
()
&&
yyLine
->
endsWith
(
QLatin1String
(
";"
))
&&
lastParen
()
==
QLatin1Char
(
'('
))
{
// ### This only checks one line back.
}
else
if
(
readLine
()
&&
yyLine
->
endsWith
(
QLatin1String
(
";"
))
&&
hasUnclosedParenOrBracket
())
{
/*
Exception:
...
...
@@ -1037,7 +1063,8 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t
indent
=
indentForStandaloneLine
();
}
if
(
okay
(
typedIn
,
QLatin1Char
(
'}'
))
&&
firstCh
==
QLatin1Char
(
'}'
))
{
if
((
okay
(
typedIn
,
QLatin1Char
(
'}'
))
&&
firstCh
==
QLatin1Char
(
'}'
))
||
(
okay
(
typedIn
,
QLatin1Char
(
']'
))
&&
firstCh
==
QLatin1Char
(
']'
)))
{
/*
A closing brace is one level more to the left than the
code it follows.
...
...
This diff is collapsed.
Click to expand it.
src/libs/qmljs/qmljsindenter.h
+
1
−
0
View file @
6a12c99b
...
...
@@ -64,6 +64,7 @@ private:
void
eraseChar
(
QString
&
t
,
int
k
,
QChar
ch
)
const
;
QChar
lastParen
()
const
;
bool
hasUnclosedParenOrBracket
()
const
;
bool
okay
(
QChar
typedIn
,
QChar
okayCh
)
const
;
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment