summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2017-04-06 17:27:52 +0200
committerRobert Loehning <robert.loehning@qt.io>2017-04-07 10:21:46 +0000
commit76dc24c3b71b28e2fa68a958239f18fb5fc2b88b (patch)
tree1f3ed0ef70320fc84bff5764b8411e685ea8f059 /src/plugins/qmljseditor
parentc643095f175bd99a2c3761083d9b3143b9aa49c4 (diff)
downloadqt-creator-76dc24c3b71b28e2fa68a958239f18fb5fc2b88b.tar.gz
QmlJSEditor: avoid jumping cursor while editing
Writing a property made the cursor jumped to the beginning. Now we only set the cursor if the textedit has not the focus and no code completion open. Change-Id: I7e5d41d5f7f9d75ebc90506d276ccaeb193c64b2 Task-number: QTCREATORBUG-15680 Task-number: QTCREATORBUG-17413 Reviewed-by: Marco Benelli <marco.benelli@qt.io> Reviewed-by: Robert Loehning <robert.loehning@qt.io>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljseditor.cpp7
-rw-r--r--src/plugins/qmljseditor/qmljseditor.h2
-rw-r--r--src/plugins/qmljseditor/qmljsoutline.cpp44
3 files changed, 32 insertions, 21 deletions
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index aea16f3d8b..cf84adfae4 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -218,6 +218,11 @@ void QmlJSEditorWidget::modificationChanged(bool changed)
m_modelManager->fileChangedOnDisk(textDocument()->filePath().toString());
}
+bool QmlJSEditorWidget::isOutlineCursorChangesBlocked()
+{
+ return hasFocus() || m_blockOutLineCursorChanges;
+}
+
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/)
{
QModelIndex index = m_outlineCombo->view()->currentIndex();
@@ -808,6 +813,7 @@ void QmlJSEditorWidget::showContextPane()
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
{
+ m_blockOutLineCursorChanges = true;
QPointer<QMenu> menu(new QMenu(this));
QMenu *refactoringMenu = new QMenu(tr("Refactoring"), menu);
@@ -852,6 +858,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
menu->exec(e->globalPos());
delete menu;
+ m_blockOutLineCursorChanges = false;
}
bool QmlJSEditorWidget::event(QEvent *e)
diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h
index 5dde3a8660..2710e29fa0 100644
--- a/src/plugins/qmljseditor/qmljseditor.h
+++ b/src/plugins/qmljseditor/qmljseditor.h
@@ -67,6 +67,7 @@ public:
QModelIndex outlineModelIndex();
void updateOutlineIndexNow();
+ bool isOutlineCursorChangesBlocked();
TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const override;
@@ -121,6 +122,7 @@ private:
QTimer m_contextPaneTimer;
QComboBox *m_outlineCombo;
QModelIndex m_outlineModelIndex;
+ bool m_blockOutLineCursorChanges = false;
QmlJS::ModelManagerInterface *m_modelManager = nullptr;
QmlJS::IContextPane *m_contextPane = nullptr;
diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp
index 26ae8b5fc6..ea90a99c66 100644
--- a/src/plugins/qmljseditor/qmljsoutline.cpp
+++ b/src/plugins/qmljseditor/qmljsoutline.cpp
@@ -195,27 +195,29 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
{
- QModelIndex sourceIndex = m_filterModel->mapToSource(index);
- AST::SourceLocation location
- = m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
-
- if (!location.isValid())
- return;
-
- const QTextBlock lastBlock = m_editor->document()->lastBlock();
- const uint textLength = lastBlock.position() + lastBlock.length();
- if (location.offset >= textLength)
- return;
-
- Core::EditorManager::cutForwardNavigationHistory();
- Core::EditorManager::addCurrentPositionToNavigationHistory();
-
- QTextCursor textCursor = m_editor->textCursor();
- m_blockCursorSync = true;
- textCursor.setPosition(location.offset);
- m_editor->setTextCursor(textCursor);
- m_editor->centerCursor();
- m_blockCursorSync = false;
+ if (!m_editor->isOutlineCursorChangesBlocked()) {
+ QModelIndex sourceIndex = m_filterModel->mapToSource(index);
+ AST::SourceLocation location
+ = m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
+
+ if (!location.isValid())
+ return;
+
+ const QTextBlock lastBlock = m_editor->document()->lastBlock();
+ const uint textLength = lastBlock.position() + lastBlock.length();
+ if (location.offset >= textLength)
+ return;
+
+ Core::EditorManager::cutForwardNavigationHistory();
+ Core::EditorManager::addCurrentPositionToNavigationHistory();
+
+ QTextCursor textCursor = m_editor->textCursor();
+ m_blockCursorSync = true;
+ textCursor.setPosition(location.offset);
+ m_editor->setTextCursor(textCursor);
+ m_editor->centerCursor();
+ m_blockCursorSync = false;
+ }
}
void QmlJSOutlineWidget::focusEditor()