From 5976ef95ea3c5651de584a9d7e8c9428dcce2d51 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 26 Mar 2024 13:58:14 +0800 Subject: [PATCH] - fix: In split screen mode, editor on the right can't be correctly found by commands. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 7 +++++++ RedPandaIDE/editor.h | 3 +++ RedPandaIDE/editorlist.cpp | 14 +++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index c3f0c740..d8befe4e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -92,6 +92,7 @@ Red Panda C++ Version 2.27 - enhancement: Auto define macro "_DEBUG" for "Debug" compiler set(like visual studio). - enhancement: Suggest macro names after "#ifdef"/"#ifndef". - enhancement: Info contents from stderr are logged into "Tools Output" panel, add problem case name info to the log. + - fix: In split screen mode, editor on the right can't be correctly found by commands. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index f7255388..69305ce5 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -95,6 +95,7 @@ Editor::Editor(QWidget *parent, const QString& filename, mHoverModifiedLine{-1}, mWheelAccumulatedDelta{0} { + mLastFocusOutTime = 0; mInited=false; mBackupFile=nullptr; mHighlightCharPos1 = QSynedit::BufferCoord{0,0}; @@ -704,6 +705,7 @@ void Editor::focusOutEvent(QFocusEvent *event) if (!pMainWindow->isQuitting()) { pMainWindow->functionTip()->hide(); } + mLastFocusOutTime = QDateTime::currentMSecsSinceEpoch(); } void Editor::keyPressEvent(QKeyEvent *event) @@ -4546,6 +4548,11 @@ void Editor::cancelHoverLink() } } +quint64 Editor::lastFocusOutTime() const +{ + return mLastFocusOutTime; +} + PCppParser Editor::sharedParser(ParserLanguage language) { PCppParser parser; diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 9cba2dec..289df7a0 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -356,6 +356,7 @@ private: int mHoverModifiedLine; int mWheelAccumulatedDelta; QMap mIdentCache; + qint64 mLastFocusOutTime; static QHash> mSharedParsers; @@ -400,6 +401,8 @@ public: bool canAutoSave() const; void setCanAutoSave(bool newCanAutoSave); + quint64 lastFocusOutTime() const; + protected: void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 82ea1db6..80287826 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -68,15 +68,23 @@ QTabWidget* EditorList::getNewEditorPageControl() const { } QTabWidget* EditorList::getFocusedPageControl() const { - //todo: switch(mLayout) { case LayoutShowType::lstLeft: return mLeftPageWidget; case LayoutShowType::lstRight: return mRightPageWidget; case LayoutShowType::lstBoth: { - Editor* editor = dynamic_cast(mRightPageWidget->currentWidget()); - if (editor && editor->hasFocus()) + Editor* rightEditor = dynamic_cast(mRightPageWidget->currentWidget()); + if (!rightEditor) + return mLeftPageWidget; + if (rightEditor->hasFocus()) + return mRightPageWidget; + Editor *leftEditor = dynamic_cast(mLeftPageWidget->currentWidget()); + if (!leftEditor) + return mRightPageWidget; + if (leftEditor->hasFocus()) + return mLeftPageWidget; + if (rightEditor->lastFocusOutTime() > leftEditor->lastFocusOutTime()) return mRightPageWidget; return mLeftPageWidget; }