Skip to content

Commit

Permalink
fix: Fixed an issue with editor document synchronization
Browse files Browse the repository at this point in the history
If newly opened files are already open in other tabwidgets, their content changes are not synchronized

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Sep 4, 2024
1 parent 39aef79 commit 1e5f38a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/plugins/codeeditor/gui/workspacewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e5f38a

Please sign in to comment.