forked from qt-creator/qt-creator
TextEditor: return all BaseTextEditor for a document
Change-Id: Iab483528357fdba1b7107130c19370974c03979c Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -208,17 +208,6 @@ void Client::openDocument(Core::IDocument *document)
|
|||||||
connect(textDocument, &QObject::destroyed, this, [this, textDocument]{
|
connect(textDocument, &QObject::destroyed, this, [this, textDocument]{
|
||||||
m_resetAssistProvider.remove(textDocument);
|
m_resetAssistProvider.remove(textDocument);
|
||||||
});
|
});
|
||||||
if (BaseTextEditor *editor = BaseTextEditor::textEditorForDocument(textDocument)) {
|
|
||||||
if (QPointer<TextEditorWidget> widget = editor->editorWidget()) {
|
|
||||||
connect(widget, &TextEditorWidget::cursorPositionChanged, this, [this, widget](){
|
|
||||||
// TODO This would better be a compressing timer
|
|
||||||
QTimer::singleShot(50, this, [this, widget]() {
|
|
||||||
if (widget)
|
|
||||||
cursorPositionChanged(widget);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_openedDocument.append(document->filePath());
|
m_openedDocument.append(document->filePath());
|
||||||
@@ -344,7 +333,7 @@ void Client::documentContentsChanged(Core::IDocument *document)
|
|||||||
|
|
||||||
if (textDocument) {
|
if (textDocument) {
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
if (BaseTextEditor *editor = BaseTextEditor::textEditorForDocument(textDocument))
|
for (BaseTextEditor *editor : BaseTextEditor::textEditorsForDocument(textDocument))
|
||||||
if (TextEditorWidget *widget = editor->editorWidget())
|
if (TextEditorWidget *widget = editor->editorWidget())
|
||||||
widget->setRefactorMarkers(RefactorMarker::filterOutType(widget->refactorMarkers(), id()));
|
widget->setRefactorMarkers(RefactorMarker::filterOutType(widget->refactorMarkers(), id()));
|
||||||
requestDocumentSymbols(textDocument);
|
requestDocumentSymbols(textDocument);
|
||||||
|
|||||||
@@ -217,6 +217,18 @@ void LanguageClientManager::editorOpened(Core::IEditor *iEditor)
|
|||||||
(const QTextCursor &cursor) {
|
(const QTextCursor &cursor) {
|
||||||
findUsages(filePath, cursor);
|
findUsages(filePath, cursor);
|
||||||
});
|
});
|
||||||
|
connect(widget, &TextEditorWidget::cursorPositionChanged, this, [this, widget](){
|
||||||
|
// TODO This would better be a compressing timer
|
||||||
|
QTimer::singleShot(50, this,
|
||||||
|
[this, widget = QPointer<TextEditorWidget>(widget)]() {
|
||||||
|
if (widget) {
|
||||||
|
for (Client *client : this->reachableClients()) {
|
||||||
|
if (client->isSupportedDocument(widget->textDocument()))
|
||||||
|
client->cursorPositionChanged(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,12 +133,10 @@ void updateCodeActionRefactoringMarker(Client *client,
|
|||||||
TextDocument* doc = TextDocument::textDocumentForFileName(uri.toFileName());
|
TextDocument* doc = TextDocument::textDocumentForFileName(uri.toFileName());
|
||||||
if (!doc)
|
if (!doc)
|
||||||
return;
|
return;
|
||||||
BaseTextEditor *editor = BaseTextEditor::textEditorForDocument(doc);
|
const QVector<BaseTextEditor *> editors = BaseTextEditor::textEditorsForDocument(doc);
|
||||||
if (!editor)
|
if (editors.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditorWidget *editorWidget = editor->editorWidget();
|
|
||||||
|
|
||||||
const QList<Diagnostic> &diagnostics = action.diagnostics().value_or(QList<Diagnostic>());
|
const QList<Diagnostic> &diagnostics = action.diagnostics().value_or(QList<Diagnostic>());
|
||||||
|
|
||||||
RefactorMarkers markers;
|
RefactorMarkers markers;
|
||||||
@@ -181,7 +179,10 @@ void updateCodeActionRefactoringMarker(Client *client,
|
|||||||
marker.cursor = endOfLineCursor(diagnostic.range().start().toTextCursor(doc->document()));
|
marker.cursor = endOfLineCursor(diagnostic.range().start().toTextCursor(doc->document()));
|
||||||
markers << marker;
|
markers << marker;
|
||||||
}
|
}
|
||||||
|
for (BaseTextEditor *editor : editors) {
|
||||||
|
if (TextEditorWidget *editorWidget = editor->editorWidget())
|
||||||
editorWidget->setRefactorMarkers(markers + editorWidget->refactorMarkers());
|
editorWidget->setRefactorMarkers(markers + editorWidget->refactorMarkers());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
|||||||
@@ -8512,13 +8512,14 @@ BaseTextEditor *BaseTextEditor::currentTextEditor()
|
|||||||
return qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
|
return qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextEditor *BaseTextEditor::textEditorForDocument(TextDocument *textDocument)
|
QVector<BaseTextEditor *> BaseTextEditor::textEditorsForDocument(TextDocument *textDocument)
|
||||||
{
|
{
|
||||||
|
QVector<BaseTextEditor *> ret;
|
||||||
for (IEditor *editor : Core::DocumentModel::editorsForDocument(textDocument)) {
|
for (IEditor *editor : Core::DocumentModel::editorsForDocument(textDocument)) {
|
||||||
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor))
|
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor))
|
||||||
return textEditor;
|
ret << textEditor;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorWidget *BaseTextEditor::editorWidget() const
|
TextEditorWidget *BaseTextEditor::editorWidget() const
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public:
|
|||||||
virtual void finalizeInitialization() {}
|
virtual void finalizeInitialization() {}
|
||||||
|
|
||||||
static BaseTextEditor *currentTextEditor();
|
static BaseTextEditor *currentTextEditor();
|
||||||
static BaseTextEditor *textEditorForDocument(TextDocument *textDocument);
|
static QVector<BaseTextEditor *> textEditorsForDocument(TextDocument *textDocument);
|
||||||
|
|
||||||
TextEditorWidget *editorWidget() const;
|
TextEditorWidget *editorWidget() const;
|
||||||
TextDocument *textDocument() const;
|
TextDocument *textDocument() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user