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
Tobias Hunger
qt-creator
Commits
0cc5f14f
Commit
0cc5f14f
authored
Oct 02, 2009
by
Christian Kamm
Browse files
Make [ start a block and trigger indentation in the qml editor.
Reviewed-by: erikv
parent
5a73440b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmleditor/qmleditor.cpp
View file @
0cc5f14f
...
...
@@ -628,7 +628,8 @@ QString ScriptEditor::wordUnderCursor() const
bool
ScriptEditor
::
isElectricCharacter
(
const
QChar
&
ch
)
const
{
if
(
ch
==
QLatin1Char
(
'}'
))
if
(
ch
==
QLatin1Char
(
'}'
)
||
ch
==
QLatin1Char
(
']'
))
return
true
;
return
false
;
}
...
...
@@ -637,12 +638,13 @@ void ScriptEditor::indentBlock(QTextDocument *, QTextBlock block, QChar typedCha
{
TextEditor
::
TabSettings
ts
=
tabSettings
();
if
(
typedChar
==
QLatin1Char
(
'}'
)
||
((
typedChar
==
QChar
::
Null
)
&&
block
.
text
().
trimmed
()
==
"}"
))
{
if
(
typedChar
==
QLatin1Char
(
'}'
)
||
typedChar
==
QLatin1Char
(
']'
)
||
(
typedChar
==
QChar
::
Null
&&
(
block
.
text
().
trimmed
()
==
"}"
||
block
.
text
().
trimmed
()
==
"]"
)))
{
QTextCursor
tc
(
block
);
if
(
typedChar
==
QLatin1Char
(
'}'
))
if
(
typedChar
==
QLatin1Char
(
'}'
)
||
typedChar
==
QLatin1Char
(
']'
)
)
tc
=
textCursor
();
if
(
TextEditor
::
TextBlockUserData
::
findPreviousBlockOpenParenthesis
(
&
tc
))
{
...
...
src/plugins/qmleditor/qmlhighlighter.cpp
View file @
0cc5f14f
...
...
@@ -63,14 +63,16 @@ int QmlHighlighter::onBlockStart()
void
QmlHighlighter
::
onOpeningParenthesis
(
QChar
parenthesis
,
int
pos
)
{
if
(
parenthesis
==
QLatin1Char
(
'{'
))
if
(
parenthesis
==
QLatin1Char
(
'{'
)
||
parenthesis
==
QLatin1Char
(
'['
))
++
m_braceDepth
;
m_currentBlockParentheses
.
push_back
(
Parenthesis
(
Parenthesis
::
Opened
,
parenthesis
,
pos
));
}
void
QmlHighlighter
::
onClosingParenthesis
(
QChar
parenthesis
,
int
pos
)
{
if
(
parenthesis
==
QLatin1Char
(
'}'
))
if
(
parenthesis
==
QLatin1Char
(
'}'
)
||
parenthesis
==
QLatin1Char
(
']'
))
--
m_braceDepth
;
m_currentBlockParentheses
.
push_back
(
Parenthesis
(
Parenthesis
::
Closed
,
parenthesis
,
pos
));
}
...
...
src/plugins/texteditor/basetexteditor.cpp
View file @
0cc5f14f
...
...
@@ -1511,9 +1511,13 @@ int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses)
int
depth
=
0
;
for
(
int
i
=
0
;
i
<
parentheses
.
size
();
++
i
)
{
const
Parenthesis
&
p
=
parentheses
.
at
(
i
);
if
(
p
.
chr
==
QLatin1Char
(
'{'
)
||
p
.
chr
==
QLatin1Char
(
'+'
))
{
if
(
p
.
chr
==
QLatin1Char
(
'{'
)
||
p
.
chr
==
QLatin1Char
(
'+'
)
||
p
.
chr
==
QLatin1Char
(
'['
))
{
++
depth
;
}
else
if
(
p
.
chr
==
QLatin1Char
(
'}'
)
||
p
.
chr
==
QLatin1Char
(
'-'
))
{
}
else
if
(
p
.
chr
==
QLatin1Char
(
'}'
)
||
p
.
chr
==
QLatin1Char
(
'-'
)
||
p
.
chr
==
QLatin1Char
(
']'
))
{
if
(
--
depth
<
0
)
return
p
.
pos
;
}
...
...
@@ -1529,13 +1533,17 @@ int Parenthesis::collapseAtPos(const Parentheses &parentheses, QChar *character)
int
depth
=
0
;
for
(
int
i
=
0
;
i
<
parentheses
.
size
();
++
i
)
{
const
Parenthesis
&
p
=
parentheses
.
at
(
i
);
if
(
p
.
chr
==
QLatin1Char
(
'{'
)
||
p
.
chr
==
QLatin1Char
(
'+'
))
{
if
(
p
.
chr
==
QLatin1Char
(
'{'
)
||
p
.
chr
==
QLatin1Char
(
'+'
)
||
p
.
chr
==
QLatin1Char
(
'['
))
{
if
(
depth
==
0
)
{
result
=
p
.
pos
;
c
=
p
.
chr
;
}
++
depth
;
}
else
if
(
p
.
chr
==
QLatin1Char
(
'}'
)
||
p
.
chr
==
QLatin1Char
(
'-'
))
{
}
else
if
(
p
.
chr
==
QLatin1Char
(
'}'
)
||
p
.
chr
==
QLatin1Char
(
'-'
)
||
p
.
chr
==
QLatin1Char
(
']'
))
{
if
(
--
depth
<
0
)
depth
=
0
;
result
=
-
1
;
...
...
@@ -1557,8 +1565,8 @@ int TextBlockUserData::braceDepthDelta() const
int
delta
=
0
;
for
(
int
i
=
0
;
i
<
m_parentheses
.
size
();
++
i
)
{
switch
(
m_parentheses
.
at
(
i
).
chr
.
unicode
())
{
case
'{'
:
case
'+'
:
++
delta
;
break
;
case
'}'
:
case
'-'
:
--
delta
;
break
;
case
'{'
:
case
'+'
:
case
'['
:
++
delta
;
break
;
case
'}'
:
case
'-'
:
case
']'
:
--
delta
;
break
;
default:
break
;
}
}
...
...
@@ -3676,7 +3684,8 @@ bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bo
for
(
int
i
=
parenList
.
count
()
-
1
;
i
>=
0
;
--
i
)
{
Parenthesis
paren
=
parenList
.
at
(
i
);
if
(
paren
.
chr
!=
QLatin1Char
(
'{'
)
&&
paren
.
chr
!=
QLatin1Char
(
'}'
)
&&
paren
.
chr
!=
QLatin1Char
(
'+'
)
&&
paren
.
chr
!=
QLatin1Char
(
'-'
))
&&
paren
.
chr
!=
QLatin1Char
(
'+'
)
&&
paren
.
chr
!=
QLatin1Char
(
'-'
)
&&
paren
.
chr
!=
QLatin1Char
(
'['
)
&&
paren
.
chr
!=
QLatin1Char
(
']'
))
continue
;
if
(
block
==
cursor
->
block
())
{
if
(
position
-
block
.
position
()
<=
paren
.
pos
+
(
paren
.
type
==
Parenthesis
::
Closed
?
1
:
0
))
...
...
@@ -3739,7 +3748,8 @@ bool TextBlockUserData::findNextBlockClosingParenthesis(QTextCursor *cursor)
for
(
int
i
=
0
;
i
<
parenList
.
count
();
++
i
)
{
Parenthesis
paren
=
parenList
.
at
(
i
);
if
(
paren
.
chr
!=
QLatin1Char
(
'{'
)
&&
paren
.
chr
!=
QLatin1Char
(
'}'
)
&&
paren
.
chr
!=
QLatin1Char
(
'+'
)
&&
paren
.
chr
!=
QLatin1Char
(
'-'
))
&&
paren
.
chr
!=
QLatin1Char
(
'+'
)
&&
paren
.
chr
!=
QLatin1Char
(
'-'
)
&&
paren
.
chr
!=
QLatin1Char
(
'['
)
&&
paren
.
chr
!=
QLatin1Char
(
']'
))
continue
;
if
(
block
==
cursor
->
block
()
&&
(
position
-
block
.
position
()
>
paren
.
pos
-
(
paren
.
type
==
Parenthesis
::
Opened
?
1
:
0
)))
...
...
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