From 55b7cb7d09ebcd9037aa7839e48c7730a2540bfb Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Tue, 3 Sep 2024 14:42:38 +0800 Subject: [PATCH] fix: Fixed an issue with editor document synchronization If newly opened files are already open in other tabwidgets, their content changes are not synchronized Log: fix issue --- src/plugins/codeeditor/gui/workspacewidget.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/codeeditor/gui/workspacewidget.cpp b/src/plugins/codeeditor/gui/workspacewidget.cpp index 6e21bd60c..28371d520 100644 --- a/src/plugins/codeeditor/gui/workspacewidget.cpp +++ b/src/plugins/codeeditor/gui/workspacewidget.cpp @@ -743,8 +743,22 @@ void WorkspaceWidgetPrivate::handleOpenFile(const QString &workspace, const QStr if (stackWidget->currentIndex() != 0) stackWidget->setCurrentIndex(0); - if (auto tabWidget = currentTabWidget()) - tabWidget->openFile(fileName); + // find the editor if the `fileName` is already opened + TextEditor *editor { nullptr }; + for (auto tabWidget : qAsConst(tabWidgetList)) { + editor = tabWidget->findEditor(fileName); + if (editor) + break; + } + + if (auto tabWidget = currentTabWidget()) { + if (editor) { + auto document = editor->document(); + tabWidget->openFile(fileName, &document); + } else { + tabWidget->openFile(fileName); + } + } } void WorkspaceWidgetPrivate::handleCloseFile(const QString &fileName)