Skip to content
GitLab
Menu
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
19890612
Commit
19890612
authored
Jan 12, 2010
by
Roberto Raggi
Browse files
Initial support of auto-brace completion in QML
parent
178d4c29
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmleditor/qmleditor.cpp
View file @
19890612
...
...
@@ -719,5 +719,98 @@ void QmlTextEditor::unCommentSelection()
Utils
::
unCommentSelection
(
this
);
}
bool
QmlTextEditor
::
contextAllowsAutoParentheses
(
const
QTextCursor
&
cursor
,
const
QString
&
textToInsert
)
const
{
if
(
isInComment
(
cursor
))
return
false
;
QChar
ch
;
if
(
!
textToInsert
.
isEmpty
())
ch
=
textToInsert
.
at
(
0
);
switch
(
ch
.
unicode
())
{
#if 0 // ### enable me
case '\'':
case '"':
#endif
case
'('
:
case
'['
:
case
'{'
:
case
')'
:
case
']'
:
case
'}'
:
case
';'
:
return
true
;
default:
if
(
ch
.
isNull
())
return
true
;
}
// end of switch
return
false
;
}
bool
QmlTextEditor
::
isInComment
(
const
QTextCursor
&
)
const
{
// ### implement me
return
false
;
}
QString
QmlTextEditor
::
insertMatchingBrace
(
const
QTextCursor
&
tc
,
const
QString
&
text
,
const
QChar
&
,
int
*
skippedChars
)
const
{
if
(
text
.
length
()
!=
1
)
return
QString
();
const
QChar
la
=
characterAt
(
tc
.
position
());
const
QChar
ch
=
text
.
at
(
0
);
switch
(
ch
.
unicode
())
{
#if 0 // ### enable me
case '\'':
if (la != ch)
return QString(ch);
++*skippedChars;
break;
case '"':
if (la != ch)
return QString(ch);
++*skippedChars;
break;
#endif
case
'('
:
return
QString
(
QLatin1Char
(
')'
));
case
'['
:
return
QString
(
QLatin1Char
(
']'
));
case
'{'
:
return
QString
();
// nothing to do.
case
')'
:
case
']'
:
case
'}'
:
case
';'
:
if
(
la
==
ch
)
++*
skippedChars
;
break
;
default:
break
;
}
// end of switch
return
QString
();
}
QString
QmlTextEditor
::
insertParagraphSeparator
(
const
QTextCursor
&
)
const
{
return
QLatin1String
(
"}
\n
"
);
}
}
// namespace Internal
}
// namespace QmlEditor
src/plugins/qmleditor/qmleditor.h
View file @
19890612
...
...
@@ -132,6 +132,12 @@ protected:
void
createToolBar
(
QmlEditorEditable
*
editable
);
TextEditor
::
BaseTextEditor
::
Link
findLinkAt
(
const
QTextCursor
&
cursor
,
bool
resolveTarget
=
true
);
//// brace matching
virtual
bool
contextAllowsAutoParentheses
(
const
QTextCursor
&
cursor
,
const
QString
&
textToInsert
=
QString
())
const
;
virtual
bool
isInComment
(
const
QTextCursor
&
cursor
)
const
;
virtual
QString
insertMatchingBrace
(
const
QTextCursor
&
tc
,
const
QString
&
text
,
const
QChar
&
la
,
int
*
skippedChars
)
const
;
virtual
QString
insertParagraphSeparator
(
const
QTextCursor
&
tc
)
const
;
private:
virtual
bool
isElectricCharacter
(
const
QChar
&
ch
)
const
;
virtual
void
indentBlock
(
QTextDocument
*
doc
,
QTextBlock
block
,
QChar
typedChar
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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