Commit 7c887960 authored by Roberto Raggi's avatar Roberto Raggi

Changed BaseTextEditor::Link to use a pair of offsets (begin, end) instead of position and length.

Done with: Thorbjorn.
parent 460c47f5
......@@ -1305,14 +1305,17 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
QTextBlock block;
const SimpleToken tk = tokenUnderCursor(tc, &block);
const int beginOfToken = block.position() + tk.begin();
const int endOfToken = block.position() + tk.end();
// Handle include directives
if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) {
const unsigned lineno = cursor.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineno && incl.resolved()) {
link.fileName = incl.fileName();
link.pos = cursor.block().position() + tk.position() + 1;
link.length = tk.length() - 2;
link.begin = beginOfToken + 1;
link.end = endOfToken - 1;
return link;
}
}
......@@ -1326,12 +1329,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
if (!lastSymbol)
return link;
const int nameStart = tk.position();
const int nameLength = tk.length();
const int endOfName = block.position() + nameStart + nameLength;
const QString name = block.text().mid(nameStart, nameLength);
tc.setPosition(endOfName);
tc.setPosition(endOfToken);
// Evaluate the type of the expression under the cursor
ExpressionUnderCursor expressionUnderCursor;
......@@ -1384,8 +1382,8 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
def = findDefinition(symbol);
link = linkToSymbol(def ? def : symbol);
link.pos = block.position() + nameStart;
link.length = nameLength;
link.begin = beginOfToken;
link.end = endOfToken;
return link;
// This would jump to the type of a name
......@@ -1400,13 +1398,13 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
}
} else {
// Handle macro uses
const Document::MacroUse *use = doc->findMacroUseAt(endOfName - 1);
const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1);
if (use) {
const Macro &macro = use->macro();
link.fileName = macro.fileName();
link.line = macro.line();
link.pos = use->begin();
link.length = use->end() - use->begin();
link.begin = use->begin();
link.end = use->end();
return link;
}
}
......
......@@ -4144,8 +4144,8 @@ void BaseTextEditor::showLink(const Link &link)
QTextEdit::ExtraSelection sel;
sel.cursor = textCursor();
sel.cursor.setPosition(link.pos);
sel.cursor.setPosition(link.pos + link.length, QTextCursor::KeepAnchor);
sel.cursor.setPosition(link.begin);
sel.cursor.setPosition(link.end, QTextCursor::KeepAnchor);
sel.format = d->m_linkFormat;
sel.format.setFontUnderline(true);
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>() << sel);
......
......@@ -567,21 +567,21 @@ protected:
Link(const QString &fileName = QString(),
int line = 0,
int column = 0)
: pos(-1)
, length(-1)
: begin(-1)
, end(-1)
, fileName(fileName)
, line(line)
, column(column)
{}
bool isValid() const
{ return !(pos == -1 || length == -1); }
{ return begin != end; }
bool operator==(const Link &other) const
{ return pos == other.pos && length == other.length; }
{ return begin == other.begin && end == other.end; }
int pos; // Link position
int length; // Link length
int begin; // Link position
int end; // Link end position
QString fileName; // Target file
int line; // Target line
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment