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]{
|
||||
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());
|
||||
@@ -344,7 +333,7 @@ void Client::documentContentsChanged(Core::IDocument *document)
|
||||
|
||||
if (textDocument) {
|
||||
using namespace TextEditor;
|
||||
if (BaseTextEditor *editor = BaseTextEditor::textEditorForDocument(textDocument))
|
||||
for (BaseTextEditor *editor : BaseTextEditor::textEditorsForDocument(textDocument))
|
||||
if (TextEditorWidget *widget = editor->editorWidget())
|
||||
widget->setRefactorMarkers(RefactorMarker::filterOutType(widget->refactorMarkers(), id()));
|
||||
requestDocumentSymbols(textDocument);
|
||||
|
||||
@@ -217,6 +217,18 @@ void LanguageClientManager::editorOpened(Core::IEditor *iEditor)
|
||||
(const QTextCursor &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());
|
||||
if (!doc)
|
||||
return;
|
||||
BaseTextEditor *editor = BaseTextEditor::textEditorForDocument(doc);
|
||||
if (!editor)
|
||||
const QVector<BaseTextEditor *> editors = BaseTextEditor::textEditorsForDocument(doc);
|
||||
if (editors.isEmpty())
|
||||
return;
|
||||
|
||||
TextEditorWidget *editorWidget = editor->editorWidget();
|
||||
|
||||
const QList<Diagnostic> &diagnostics = action.diagnostics().value_or(QList<Diagnostic>());
|
||||
|
||||
RefactorMarkers markers;
|
||||
@@ -181,7 +179,10 @@ void updateCodeActionRefactoringMarker(Client *client,
|
||||
marker.cursor = endOfLineCursor(diagnostic.range().start().toTextCursor(doc->document()));
|
||||
markers << marker;
|
||||
}
|
||||
for (BaseTextEditor *editor : editors) {
|
||||
if (TextEditorWidget *editorWidget = editor->editorWidget())
|
||||
editorWidget->setRefactorMarkers(markers + editorWidget->refactorMarkers());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
||||
@@ -8512,13 +8512,14 @@ BaseTextEditor *BaseTextEditor::currentTextEditor()
|
||||
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)) {
|
||||
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor))
|
||||
return textEditor;
|
||||
ret << textEditor;
|
||||
}
|
||||
return nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
TextEditorWidget *BaseTextEditor::editorWidget() const
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
virtual void finalizeInitialization() {}
|
||||
|
||||
static BaseTextEditor *currentTextEditor();
|
||||
static BaseTextEditor *textEditorForDocument(TextDocument *textDocument);
|
||||
static QVector<BaseTextEditor *> textEditorsForDocument(TextDocument *textDocument);
|
||||
|
||||
TextEditorWidget *editorWidget() const;
|
||||
TextDocument *textDocument() const;
|
||||
|
||||
Reference in New Issue
Block a user