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
eaecfb7e
Commit
eaecfb7e
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Fixed auto-quote completion at the end of unfinished string literals.
parent
7baecce0
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/plugins/qmleditor/qmleditor.cpp
+26
-8
26 additions, 8 deletions
src/plugins/qmleditor/qmleditor.cpp
src/plugins/qtscripteditor/qtscripteditor.cpp
+26
-8
26 additions, 8 deletions
src/plugins/qtscripteditor/qtscripteditor.cpp
with
52 additions
and
16 deletions
src/plugins/qmleditor/qmleditor.cpp
+
26
−
8
View file @
eaecfb7e
...
...
@@ -691,6 +691,19 @@ void QmlTextEditor::unCommentSelection()
Utils
::
unCommentSelection
(
this
);
}
static
bool
isCompleteStringLiteral
(
const
QStringRef
&
text
)
{
if
(
text
.
length
()
<
2
)
return
false
;
const
QChar
quote
=
text
.
at
(
0
);
if
(
text
.
at
(
text
.
length
()
-
1
)
==
quote
)
return
text
.
at
(
text
.
length
()
-
2
)
!=
QLatin1Char
(
'\\'
);
// ### not exactly.
return
false
;
}
bool
QmlTextEditor
::
contextAllowsAutoParentheses
(
const
QTextCursor
&
cursor
,
const
QString
&
textToInsert
)
const
{
QChar
ch
;
...
...
@@ -727,18 +740,21 @@ bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, cons
const
QList
<
QScriptIncrementalScanner
::
Token
>
tokens
=
tokenize
(
blockText
,
blockState
);
const
int
pos
=
cursor
.
columnNumber
();
int
tokenIndex
=
tokens
.
size
()
-
1
;
for
(;
tokenIndex
!=
-
1
;
--
tokenIndex
)
{
int
tokenIndex
=
0
;
for
(;
tokenIndex
<
tokens
.
size
();
++
tokenIndex
)
{
const
QScriptIncrementalScanner
::
Token
&
token
=
tokens
.
at
(
tokenIndex
);
if
(
pos
>=
token
.
begin
())
{
if
(
pos
<
token
.
end
())
break
;
else
if
(
pos
==
token
.
end
()
&&
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
else
if
(
pos
==
token
.
end
()
&&
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
)
||
token
.
is
(
QScriptIncrementalScanner
::
Token
::
String
)))
break
;
}
}
if
(
tokenIndex
!=
-
1
)
{
if
(
tokenIndex
!=
tokens
.
size
()
)
{
const
QScriptIncrementalScanner
::
Token
&
token
=
tokens
.
at
(
tokenIndex
);
switch
(
token
.
kind
)
{
...
...
@@ -746,10 +762,12 @@ bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, cons
return
false
;
case
QScriptIncrementalScanner
::
Token
::
String
:
{
if
(
ch
==
blockText
.
at
(
token
.
begin
()))
{
if
(
token
.
end
()
-
1
==
pos
&&
blockText
.
at
(
token
.
end
()
-
2
)
!=
QLatin1Char
(
'\\'
))
break
;
}
const
QStringRef
tokenText
=
blockText
.
midRef
(
token
.
offset
,
token
.
length
);
const
QChar
quote
=
tokenText
.
at
(
0
);
if
(
ch
==
quote
&&
isCompleteStringLiteral
(
tokenText
))
break
;
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
src/plugins/qtscripteditor/qtscripteditor.cpp
+
26
−
8
View file @
eaecfb7e
...
...
@@ -402,6 +402,19 @@ void ScriptEditor::unCommentSelection()
Utils
::
unCommentSelection
(
this
);
}
static
bool
isCompleteStringLiteral
(
const
QStringRef
&
text
)
{
if
(
text
.
length
()
<
2
)
return
false
;
const
QChar
quote
=
text
.
at
(
0
);
if
(
text
.
at
(
text
.
length
()
-
1
)
==
quote
)
return
text
.
at
(
text
.
length
()
-
2
)
!=
QLatin1Char
(
'\\'
);
// ### not exactly.
return
false
;
}
bool
ScriptEditor
::
contextAllowsAutoParentheses
(
const
QTextCursor
&
cursor
,
const
QString
&
textToInsert
)
const
{
QChar
ch
;
...
...
@@ -442,18 +455,21 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
const
QList
<
QScriptIncrementalScanner
::
Token
>
tokens
=
tokenize
(
blockText
,
blockState
);
const
int
pos
=
cursor
.
columnNumber
();
int
tokenIndex
=
tokens
.
size
()
-
1
;
for
(;
tokenIndex
!=
-
1
;
--
tokenIndex
)
{
int
tokenIndex
=
0
;
for
(;
tokenIndex
<
tokens
.
size
();
++
tokenIndex
)
{
const
QScriptIncrementalScanner
::
Token
&
token
=
tokens
.
at
(
tokenIndex
);
if
(
pos
>=
token
.
begin
())
{
if
(
pos
<
token
.
end
())
break
;
else
if
(
pos
==
token
.
end
()
&&
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
))
else
if
(
pos
==
token
.
end
()
&&
(
token
.
is
(
QScriptIncrementalScanner
::
Token
::
Comment
)
||
token
.
is
(
QScriptIncrementalScanner
::
Token
::
String
)))
break
;
}
}
if
(
tokenIndex
!=
-
1
)
{
if
(
tokenIndex
!=
tokens
.
size
()
)
{
const
QScriptIncrementalScanner
::
Token
&
token
=
tokens
.
at
(
tokenIndex
);
switch
(
token
.
kind
)
{
...
...
@@ -461,10 +477,12 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
return
false
;
case
QScriptIncrementalScanner
::
Token
::
String
:
{
if
(
ch
==
blockText
.
at
(
token
.
begin
()))
{
if
(
token
.
end
()
-
1
==
pos
&&
blockText
.
at
(
token
.
end
()
-
2
)
!=
QLatin1Char
(
'\\'
))
break
;
}
const
QStringRef
tokenText
=
blockText
.
midRef
(
token
.
offset
,
token
.
length
);
const
QChar
quote
=
tokenText
.
at
(
0
);
if
(
ch
==
quote
&&
isCompleteStringLiteral
(
tokenText
))
break
;
return
false
;
}
...
...
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