Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
b9ce92ec
Commit
b9ce92ec
authored
Sep 21, 2009
by
Roberto Raggi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove all the synthesized characters when matching curly braces
parent
29f03c75
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
14 deletions
+30
-14
src/libs/cplusplus/MatchingText.cpp
src/libs/cplusplus/MatchingText.cpp
+10
-4
src/libs/cplusplus/MatchingText.h
src/libs/cplusplus/MatchingText.h
+3
-0
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+17
-10
No files found.
src/libs/cplusplus/MatchingText.cpp
View file @
b9ce92ec
...
...
@@ -75,7 +75,16 @@ static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index)
return
false
;
}
static
bool
shouldInsertMatchingText
(
const
QChar
&
lookAhead
)
MatchingText
::
MatchingText
()
{
}
bool
MatchingText
::
shouldInsertMatchingText
(
const
QTextCursor
&
tc
)
{
QTextDocument
*
doc
=
tc
.
document
();
return
shouldInsertMatchingText
(
doc
->
characterAt
(
tc
.
selectionEnd
()));
}
bool
MatchingText
::
shouldInsertMatchingText
(
const
QChar
&
lookAhead
)
{
switch
(
lookAhead
.
unicode
())
{
case
'{'
:
case
'}'
:
...
...
@@ -91,9 +100,6 @@ static bool shouldInsertMatchingText(const QChar &lookAhead)
}
// switch
}
MatchingText
::
MatchingText
()
{
}
QString
MatchingText
::
insertMatchingBrace
(
const
QTextCursor
&
cursor
,
const
QString
&
textToProcess
,
const
QChar
&
la
,
int
*
skippedChars
)
const
{
...
...
src/libs/cplusplus/MatchingText.h
View file @
b9ce92ec
...
...
@@ -41,6 +41,9 @@ class CPLUSPLUS_EXPORT MatchingText
public:
MatchingText
();
static
bool
shouldInsertMatchingText
(
const
QTextCursor
&
tc
);
static
bool
shouldInsertMatchingText
(
const
QChar
&
lookAhead
);
QString
insertMatchingBrace
(
const
QTextCursor
&
tc
,
const
QString
&
text
,
const
QChar
&
la
,
int
*
skippedChars
)
const
;
QString
insertParagraphSeparator
(
const
QTextCursor
&
tc
)
const
;
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
b9ce92ec
...
...
@@ -1273,8 +1273,8 @@ bool CPPEditor::isElectricCharacter(const QChar &ch) const
QString
CPPEditor
::
autoComplete
(
QTextCursor
&
cursor
,
const
QString
&
textToInsert
)
const
{
bool
checkBlockEnd
=
m_allowSkippingOfBlockEnd
;
m_allowSkippingOfBlockEnd
=
false
;
const
bool
checkBlockEnd
=
m_allowSkippingOfBlockEnd
;
m_allowSkippingOfBlockEnd
=
false
;
// consume blockEnd.
if
(
!
contextAllowsAutoParentheses
(
cursor
))
return
QString
();
...
...
@@ -1282,16 +1282,21 @@ QString CPPEditor::autoComplete(QTextCursor &cursor, const QString &textToInsert
QString
text
=
textToInsert
;
const
QChar
lookAhead
=
characterAt
(
cursor
.
selectionEnd
());
QString
auto
Text
;
MatchingText
matching
Text
;
int
skippedChars
=
0
;
const
QString
autoText
=
matchingText
.
insertMatchingBrace
(
cursor
,
text
,
lookAhead
,
&
skippedChars
);
if
(
checkBlockEnd
&&
(
lookAhead
==
QChar
::
ParagraphSeparator
&&
(
!
text
.
isEmpty
()
&&
text
.
at
(
0
)
==
QLatin1Char
(
'}'
))))
{
skippedChars
=
2
;
text
=
text
.
mid
(
1
);
}
if
(
checkBlockEnd
&&
textToInsert
.
at
(
0
)
==
QLatin1Char
(
'}'
))
{
if
(
textToInsert
.
length
()
>
1
)
qWarning
()
<<
"*** handle event compression"
;
MatchingText
matchingText
;
autoText
=
matchingText
.
insertMatchingBrace
(
cursor
,
text
,
lookAhead
,
&
skippedChars
);
int
startPos
=
cursor
.
selectionEnd
(),
pos
=
startPos
;
while
(
characterAt
(
pos
).
isSpace
())
++
pos
;
if
(
characterAt
(
pos
)
==
QLatin1Char
(
'}'
))
skippedChars
+=
(
pos
-
startPos
)
+
1
;
}
if
(
skippedChars
)
{
const
int
pos
=
cursor
.
position
();
...
...
@@ -1338,7 +1343,6 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
if
(
!
contextAllowsAutoParentheses
(
cursor
))
return
0
;
// verify that we indeed do have an extra opening brace in the document
int
braceDepth
=
document
()
->
lastBlock
().
userState
();
if
(
braceDepth
>=
0
)
...
...
@@ -1372,6 +1376,9 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
bool
CPPEditor
::
contextAllowsAutoParentheses
(
const
QTextCursor
&
cursor
)
const
{
if
(
!
MatchingText
::
shouldInsertMatchingText
(
cursor
))
return
false
;
CPlusPlus
::
TokenUnderCursor
tokenUnderCursor
;
const
SimpleToken
tk
=
tokenUnderCursor
(
cursor
);
...
...
Write
Preview
Markdown
is supported
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