From 8307f1b38faf646ba20e5f02a845e9a1eb0abdbd Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 22 Mar 2024 20:32:48 +0800 Subject: [PATCH] - enhancement: Restore line position after file is modified outside and reloaded. --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index ba764a35..421c419a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -78,6 +78,7 @@ Red Panda C++ Version 2.27 - fix: History not correctly loaded with up/down arrow key in the debug console. - enhancement: Improve lambda support. - enhancement: Show type completion hint after "constexpr"/"extern"/"static"/"consteval"/"constinit"/"const"/"volatile" etc. + - enhancement: Restore line position after file is modified outside and reloaded. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 595c0bf9..16948729 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -5482,7 +5482,11 @@ void MainWindow::onFileChanged(const QString &path) QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) { try { + int topLine = e->topLine(); + QSynedit::BufferCoord caretPos = e->caretXY(); e->loadFile(); + e->setCaretPositionAndActivate(caretPos.line,1); + e->setTopLine(topLine); } catch(FileError e) { QMessageBox::critical(this,tr("Error"),e.reason()); }