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
ea9f96a3
Commit
ea9f96a3
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Improved QML/JS indenter when using C-like multiline comments.
parent
35e35268
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/shared/qscripthighlighter/qscriptindenter.cpp
+31
-36
31 additions, 36 deletions
src/shared/qscripthighlighter/qscriptindenter.cpp
src/shared/qscripthighlighter/qscriptindenter.h
+2
-2
2 additions, 2 deletions
src/shared/qscripthighlighter/qscriptindenter.h
with
33 additions
and
38 deletions
src/shared/qscripthighlighter/qscriptindenter.cpp
+
31
−
36
View file @
ea9f96a3
...
@@ -208,12 +208,10 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
...
@@ -208,12 +208,10 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
{
{
QScriptIncrementalScanner
scanner
;
QScriptIncrementalScanner
scanner
;
int
state
=
yyLinizerState
.
iter
.
userState
();
QTextBlock
currentLine
=
yyLinizerState
.
iter
;
if
(
state
==
-
1
)
int
startState
=
qMax
(
0
,
currentLine
.
previous
().
userState
())
&
0xff
;
state
=
0
;
state
=
state
&
0xff
;
yyLinizerState
.
tokens
=
scanner
(
t
,
state
);
yyLinizerState
.
tokens
=
scanner
(
t
,
sta
rtSta
te
);
QString
trimmed
;
QString
trimmed
;
int
previousTokenEnd
=
0
;
int
previousTokenEnd
=
0
;
foreach
(
const
QScriptIncrementalScanner
::
Token
&
token
,
yyLinizerState
.
tokens
)
{
foreach
(
const
QScriptIncrementalScanner
::
Token
&
token
,
yyLinizerState
.
tokens
)
{
...
@@ -224,8 +222,25 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
...
@@ -224,8 +222,25 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
trimmed
.
append
(
QLatin1Char
(
'X'
));
trimmed
.
append
(
QLatin1Char
(
'X'
));
}
else
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
{
}
else
if
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
{
for
(
int
i
=
0
;
i
<
token
.
length
;
++
i
)
int
i
=
0
;
trimmed
.
append
(
QLatin1Char
(
' '
));
int
e
=
token
.
length
;
if
(
token
.
offset
>
0
||
startState
==
0
)
{
trimmed
.
append
(
QLatin1String
(
"/*"
));
i
+=
2
;
}
bool
needEndOfComment
=
false
;
if
(
e
>
2
&&
token
.
end
()
==
t
.
length
()
&&
scanner
.
endState
()
!=
0
)
{
needEndOfComment
=
true
;
e
-=
2
;
}
for
(;
i
<
e
;
++
i
)
trimmed
.
append
(
QLatin1Char
(
' '
));
if
(
needEndOfComment
)
trimmed
.
append
(
QLatin1String
(
"*/"
));
}
else
{
}
else
{
trimmed
.
append
(
t
.
midRef
(
token
.
offset
,
token
.
length
));
trimmed
.
append
(
t
.
midRef
(
token
.
offset
,
token
.
length
));
...
@@ -450,35 +465,15 @@ void QScriptIndenter::startLinizer()
...
@@ -450,35 +465,15 @@ void QScriptIndenter::startLinizer()
potentially the whole line) is part of a C-style comment;
potentially the whole line) is part of a C-style comment;
otherwise returns false.
otherwise returns false.
*/
*/
bool
QScriptIndenter
::
bottomLineStartsIn
C
Comment
()
bool
QScriptIndenter
::
bottomLineStartsIn
Multiline
Comment
()
{
{
const
QLatin1String
slashAster
(
"/*"
);
QTextBlock
currentLine
=
yyProgram
.
lastBlock
().
previous
();
const
QLatin1String
asterSlash
(
"*/"
);
QTextBlock
previousLine
=
currentLine
.
previous
();
/*
We could use the linizer here, but that would slow us down
terribly. We are better to trim only the code lines we need.
*/
QTextBlock
p
=
yyProgram
.
lastBlock
();
p
=
p
.
previous
();
// skip bottom line
for
(
int
i
=
0
;
i
<
BigRoof
;
i
++
)
{
if
(
p
==
yyProgram
.
firstBlock
())
return
false
;
p
=
p
.
previous
();
const
QString
blockText
=
p
.
text
();
if
(
blockText
.
indexOf
(
slashAster
)
!=
-
1
||
blockText
.
indexOf
(
asterSlash
)
!=
-
1
)
{
int
startState
=
qMax
(
0
,
previousLine
.
userState
())
&
0xff
;
const
QString
trimmed
=
trimmedCodeLine
(
blockText
);
if
(
startState
>
0
)
return
true
;
if
(
trimmed
.
indexOf
(
slashAster
)
!=
-
1
)
{
return
true
;
}
else
if
(
trimmed
.
indexOf
(
asterSlash
)
!=
-
1
)
{
return
false
;
}
}
}
return
false
;
return
false
;
}
}
...
@@ -490,7 +485,7 @@ bool QScriptIndenter::bottomLineStartsInCComment()
...
@@ -490,7 +485,7 @@ bool QScriptIndenter::bottomLineStartsInCComment()
Essentially, we're trying to align against some text on the
Essentially, we're trying to align against some text on the
previous line.
previous line.
*/
*/
int
QScriptIndenter
::
indentWhenBottomLineStartsIn
C
Comment
()
int
QScriptIndenter
::
indentWhenBottomLineStartsIn
MultiLine
Comment
()
{
{
int
k
=
yyLine
->
lastIndexOf
(
QLatin1String
(
"/*"
));
int
k
=
yyLine
->
lastIndexOf
(
QLatin1String
(
"/*"
));
if
(
k
==
-
1
)
{
if
(
k
==
-
1
)
{
...
@@ -1028,14 +1023,14 @@ int QScriptIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar
...
@@ -1028,14 +1023,14 @@ int QScriptIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar
QChar
firstCh
=
firstNonWhiteSpace
(
bottomLine
);
QChar
firstCh
=
firstNonWhiteSpace
(
bottomLine
);
int
indent
=
0
;
int
indent
=
0
;
if
(
bottomLineStartsIn
C
Comment
())
{
if
(
bottomLineStartsIn
Multiline
Comment
())
{
/*
/*
The bottom line starts in a C-style comment. Indent it
The bottom line starts in a C-style comment. Indent it
smartly, unless the user has already played around with it,
smartly, unless the user has already played around with it,
in which case it's better to leave her stuff alone.
in which case it's better to leave her stuff alone.
*/
*/
if
(
isOnlyWhiteSpace
(
bottomLine
))
{
if
(
isOnlyWhiteSpace
(
bottomLine
))
{
indent
=
indentWhenBottomLineStartsIn
C
Comment
();
indent
=
indentWhenBottomLineStartsIn
MultiLine
Comment
();
}
else
{
}
else
{
indent
=
indentOfLine
(
bottomLine
);
indent
=
indentOfLine
(
bottomLine
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/shared/qscripthighlighter/qscriptindenter.h
+
2
−
2
View file @
ea9f96a3
...
@@ -74,8 +74,8 @@ private:
...
@@ -74,8 +74,8 @@ private:
bool
readLine
();
bool
readLine
();
void
startLinizer
();
void
startLinizer
();
bool
bottomLineStartsIn
C
Comment
();
bool
bottomLineStartsIn
Multiline
Comment
();
int
indentWhenBottomLineStartsIn
C
Comment
();
int
indentWhenBottomLineStartsIn
MultiLine
Comment
();
bool
matchBracelessControlStatement
();
bool
matchBracelessControlStatement
();
bool
isUnfinishedLine
();
bool
isUnfinishedLine
();
bool
isContinuationLine
();
bool
isContinuationLine
();
...
...
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