aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpptools/cppeditoroutline.cpp
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-06-01 09:18:45 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-06-04 08:43:44 +0000
commitb0c01193457ef931577a7b4d850c22826c91ac01 (patch)
treea3fbefb8f807d8bccdd16563541d1b33d251c3ef /src/plugins/cpptools/cppeditoroutline.cpp
parent92530fd05dfe596810e90b499d399f1859bdfd56 (diff)
CppTools: Use cursor range for better outline navigation
Clang provides cursor range for each declaration in symbol outline. Use that information to search for more accurate correspondence between a cursor position in editor and an entry in symbol outline. For example skip indexes with not matching ranges to prevent pure declarations from automatically become parents of everything coming after them. Change-Id: I0ef95c26772050cd6655e830288c46118aba38bb Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppeditoroutline.cpp')
-rw-r--r--src/plugins/cpptools/cppeditoroutline.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppeditoroutline.cpp b/src/plugins/cpptools/cppeditoroutline.cpp
index a71e027cdc..d7840016d5 100644
--- a/src/plugins/cpptools/cppeditoroutline.cpp
+++ b/src/plugins/cpptools/cppeditoroutline.cpp
@@ -263,6 +263,17 @@ void CppEditorOutline::gotoSymbolInEditor()
emit m_editorWidget->activateEditor();
}
+static bool contains(const AbstractOverviewModel::Range &range, int line, int column)
+{
+ if (line < range.first.line || line > range.second.line)
+ return false;
+ if (line == range.first.line && column < range.first.column)
+ return false;
+ if (line == range.second.line && column > range.second.column)
+ return false;
+ return true;
+}
+
QModelIndex CppEditorOutline::indexForPosition(int line, int column,
const QModelIndex &rootIndex) const
{
@@ -270,8 +281,12 @@ QModelIndex CppEditorOutline::indexForPosition(int line, int column,
const int rowCount = m_model->rowCount(rootIndex);
for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = m_model->index(row, 0, rootIndex);
- if (m_model->lineColumnFromIndex(index).line > line)
+ const AbstractOverviewModel::Range range = m_model->rangeFromIndex(index);
+ if (range.first.line > line)
break;
+ // Skip ranges that do not include current line and column.
+ if (range.second != range.first && !contains(range, line, column))
+ continue;
lastIndex = index;
}