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
68d8d830
Commit
68d8d830
authored
Mar 30, 2009
by
Roberto Raggi
Browse files
Simplified the code that looks for the identifier under the cursor.
parent
19494366
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/libs/cplusplus/TokenUnderCursor.cpp
View file @
68d8d830
...
...
@@ -42,7 +42,7 @@ TokenUnderCursor::TokenUnderCursor()
TokenUnderCursor
::~
TokenUnderCursor
()
{
}
SimpleToken
TokenUnderCursor
::
operator
()(
const
QTextCursor
&
cursor
)
const
SimpleToken
TokenUnderCursor
::
operator
()(
const
QTextCursor
&
cursor
,
QTextBlock
*
b
)
const
{
SimpleLexer
tokenize
;
tokenize
.
setObjCEnabled
(
true
);
...
...
@@ -54,8 +54,11 @@ SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor) const
QList
<
SimpleToken
>
tokens
=
tokenize
(
block
.
text
(),
previousBlockState
(
block
));
for
(
int
index
=
tokens
.
size
()
-
1
;
index
!=
-
1
;
--
index
)
{
const
SimpleToken
&
tk
=
tokens
.
at
(
index
);
if
(
tk
.
position
()
<
column
)
if
(
tk
.
position
()
<
column
)
{
if
(
b
)
*
b
=
block
;
return
tk
;
}
}
return
SimpleToken
();
...
...
src/libs/cplusplus/TokenUnderCursor.h
View file @
68d8d830
...
...
@@ -48,7 +48,7 @@ public:
TokenUnderCursor
();
~
TokenUnderCursor
();
SimpleToken
operator
()(
const
QTextCursor
&
cursor
)
const
;
SimpleToken
operator
()(
const
QTextCursor
&
cursor
,
QTextBlock
*
block
=
0
)
const
;
private:
int
previousBlockState
(
const
QTextBlock
&
block
)
const
;
...
...
src/plugins/cppeditor/cppeditor.cpp
View file @
68d8d830
...
...
@@ -618,24 +618,27 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
if
(
!
lastSymbol
)
return
link
;
// Check whether we're at a name
const
int
endOfName
=
endOfNameAtPosition
(
cursor
.
position
());
if
(
!
characterAt
(
endOfName
-
1
).
isLetterOrNumber
())
return
link
;
// Remember the position and length of the name
QTextCursor
tc
=
cursor
;
tc
.
setPosition
(
endOfName
);
tc
.
movePosition
(
QTextCursor
::
PreviousWord
,
QTextCursor
::
KeepAnchor
);
const
int
nameStart
=
tc
.
position
();
const
int
nameLength
=
tc
.
anchor
()
-
tc
.
position
();
tc
.
setPosition
(
endOfName
);
// Drop out if we're at a number, string or comment
static
TokenUnderCursor
tokenUnderCursor
;
const
SimpleToken
tk
=
tokenUnderCursor
(
tc
);
if
(
tk
.
isLiteral
()
||
tk
.
isComment
())
QTextBlock
block
;
const
SimpleToken
tk
=
tokenUnderCursor
(
tc
,
&
block
);
if
(
tk
.
isLiteral
()
||
tk
.
isComment
())
{
// Drop out if we're at a number, string or comment
return
link
;
}
if
(
tk
.
isNot
(
T_IDENTIFIER
))
return
link
;
const
int
nameStart
=
tk
.
position
();
const
int
nameLength
=
tk
.
length
();
const
int
endOfName
=
nameStart
+
nameLength
;
const
QString
name
=
block
.
text
().
mid
(
nameStart
,
nameLength
);
tc
.
setPosition
(
block
.
position
()
+
endOfName
);
// Evaluate the type of the expression under the cursor
ExpressionUnderCursor
expressionUnderCursor
;
...
...
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