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>
This commit is contained in:
Tim Jenssen
2017-04-06 17:27:52 +02:00
committed by Robert Loehning
parent c643095f17
commit 76dc24c3b7
3 changed files with 28 additions and 17 deletions

View File

@@ -218,6 +218,11 @@ void QmlJSEditorWidget::modificationChanged(bool changed)
m_modelManager->fileChangedOnDisk(textDocument()->filePath().toString()); m_modelManager->fileChangedOnDisk(textDocument()->filePath().toString());
} }
bool QmlJSEditorWidget::isOutlineCursorChangesBlocked()
{
return hasFocus() || m_blockOutLineCursorChanges;
}
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/) void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/)
{ {
QModelIndex index = m_outlineCombo->view()->currentIndex(); QModelIndex index = m_outlineCombo->view()->currentIndex();
@@ -808,6 +813,7 @@ void QmlJSEditorWidget::showContextPane()
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e) void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
{ {
m_blockOutLineCursorChanges = true;
QPointer<QMenu> menu(new QMenu(this)); QPointer<QMenu> menu(new QMenu(this));
QMenu *refactoringMenu = new QMenu(tr("Refactoring"), menu); QMenu *refactoringMenu = new QMenu(tr("Refactoring"), menu);
@@ -852,6 +858,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
menu->exec(e->globalPos()); menu->exec(e->globalPos());
delete menu; delete menu;
m_blockOutLineCursorChanges = false;
} }
bool QmlJSEditorWidget::event(QEvent *e) bool QmlJSEditorWidget::event(QEvent *e)

View File

@@ -67,6 +67,7 @@ public:
QModelIndex outlineModelIndex(); QModelIndex outlineModelIndex();
void updateOutlineIndexNow(); void updateOutlineIndexNow();
bool isOutlineCursorChangesBlocked();
TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const override; TextEditor::AssistReason reason) const override;
@@ -121,6 +122,7 @@ private:
QTimer m_contextPaneTimer; QTimer m_contextPaneTimer;
QComboBox *m_outlineCombo; QComboBox *m_outlineCombo;
QModelIndex m_outlineModelIndex; QModelIndex m_outlineModelIndex;
bool m_blockOutLineCursorChanges = false;
QmlJS::ModelManagerInterface *m_modelManager = nullptr; QmlJS::ModelManagerInterface *m_modelManager = nullptr;
QmlJS::IContextPane *m_contextPane = nullptr; QmlJS::IContextPane *m_contextPane = nullptr;

View File

@@ -195,6 +195,7 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index) void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
{ {
if (!m_editor->isOutlineCursorChangesBlocked()) {
QModelIndex sourceIndex = m_filterModel->mapToSource(index); QModelIndex sourceIndex = m_filterModel->mapToSource(index);
AST::SourceLocation location AST::SourceLocation location
= m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex); = m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
@@ -217,6 +218,7 @@ void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
m_editor->centerCursor(); m_editor->centerCursor();
m_blockCursorSync = false; m_blockCursorSync = false;
} }
}
void QmlJSOutlineWidget::focusEditor() void QmlJSOutlineWidget::focusEditor()
{ {