From dad39f6f7457b40428ed97ff5c7f576c2f68e50c Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 10 Mar 2022 12:15:44 +0800 Subject: [PATCH] - change: "locate in files view" won't change the working folder, if current file is in subfolders of the working folder - enhancement: hide function tips, when input method is visible --- NEWS.md | 2 ++ RedPandaIDE/editor.cpp | 22 +++++++++++++++++++--- RedPandaIDE/editor.h | 4 +++- RedPandaIDE/mainwindow.cpp | 20 ++++++++++++-------- RedPandaIDE/qsynedit/SynEdit.cpp | 14 ++++++-------- RedPandaIDE/qsynedit/SynEdit.h | 7 +++---- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/NEWS.md b/NEWS.md index 27e9b863..df0834f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,8 @@ Red Panda C++ Version 0.14.5 - fix: save project's layout shouldn't modify the project file - enhancement: use expression processing in syntax highlighting for identifiers - fix: if a function's declaration can't be found, it will be wrongly highlighted as variable + - change: "locate in files view" won't change the working folder, if current file is in subfolders of the working folder + - enhancement: hide function tips, when input method is visible Red Panda C++ Version 0.14.4 - enhancement: git - log diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 07449cd5..3f57930b 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -178,6 +178,8 @@ Editor::Editor(QWidget *parent, const QString& filename, mParentPageControl->addTab(this,""); updateCaption(); } + connect(&mFunctionTipTimer, &QTimer::timeout, + this, &Editor::onFunctionTipsTimer); } Editor::~Editor() { @@ -1548,7 +1550,10 @@ void Editor::onStatusChanged(SynStatusChanges changes) // Update the function tip if (pSettings->editor().showFunctionTips()) { - updateFunctionTip(); + updateFunctionTip(false); + mFunctionTipTimer.stop(); + mFunctionTipTimer.start(500); +// updateFunctionTip(); } } @@ -1612,6 +1617,12 @@ void Editor::onLinesInserted(int first, int count) } } +void Editor::onFunctionTipsTimer() +{ + mFunctionTipTimer.stop(); + updateFunctionTip(true); +} + bool Editor::isBraceChar(QChar ch) { switch( ch.unicode()) { @@ -3367,12 +3378,16 @@ QString Editor::getHintForFunction(const PStatement &statement, const PStatement return result; } -void Editor::updateFunctionTip() +void Editor::updateFunctionTip(bool showTip) { if (pMainWindow->completionPopup()->isVisible()) { pMainWindow->functionTip()->hide(); return; } + if (inputMethodOn()) { + pMainWindow->functionTip()->hide(); + return; + } if (!highlighter()) return; @@ -3571,7 +3586,8 @@ void Editor::updateFunctionTip() currentParamPos ); cancelHint(); - pMainWindow->functionTip()->show(); + if (showTip) + pMainWindow->functionTip()->show(); } void Editor::clearUserCodeInTabStops() diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 9eb62ed5..b0442eaf 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -232,6 +232,7 @@ private slots: void onTipEvalValueReady(const QString& value); void onLinesDeleted(int first,int count); void onLinesInserted(int first,int count); + void onFunctionTipsTimer(); private: bool isBraceChar(QChar ch); @@ -277,7 +278,7 @@ private: QString getHintForFunction(const PStatement& statement, const PStatement& scope, const QString& filename, int line); - void updateFunctionTip(); + void updateFunctionTip(bool showTip); void clearUserCodeInTabStops(); void popUserCodeInTabStops(); void onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, int column, const QString& token, @@ -329,6 +330,7 @@ private: BufferCoord mHighlightCharPos1; BufferCoord mHighlightCharPos2; std::shared_ptr > > mStatementColors; + QTimer mFunctionTipTimer; // QWidget interface protected: diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index aa21d07b..ed88b23f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -6216,15 +6216,19 @@ void MainWindow::on_actionLocate_in_Files_View_triggered() { Editor * editor = mEditorList->getEditor(); if (editor) { - QString fileDir = extractFileDir(editor->filename()); - if (!fileDir.isEmpty()) { - setFilesViewRoot(fileDir); - QModelIndex index = mFileSystemModel.index(editor->filename()); - ui->treeFiles->setCurrentIndex(index); - ui->treeFiles->scrollTo(index, QAbstractItemView::PositionAtCenter); - ui->tabInfos->setCurrentWidget(ui->tabFiles); - openCloseLeftPanel(true); + QModelIndex index = mFileSystemModel.index(editor->filename()); + if (!index.isValid()) { + QString fileDir = extractFileDir(editor->filename()); + if (!fileDir.isEmpty()) + setFilesViewRoot(fileDir); + else + return; + index = mFileSystemModel.index(editor->filename()); } + ui->treeFiles->setCurrentIndex(index); + ui->treeFiles->scrollTo(index, QAbstractItemView::PositionAtCenter); + ui->tabInfos->setCurrentWidget(ui->tabFiles); + openCloseLeftPanel(true); } } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 1b6f7beb..73b88671 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -122,10 +122,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) setDefaultKeystrokes(); mRightEdgeColor = Qt::lightGray; - /* IME input */ - mImeCount = 0; - mMBCSStepAside = false; - /* end of IME input */ mWantReturns = true; mWantTabs = false; mTabWidth = 4; @@ -1095,6 +1091,11 @@ void SynEdit::setCaretAndSelection(const BufferCoord &ptCaret, const BufferCoord setBlockEnd(ptAfter); } +bool SynEdit::inputMethodOn() +{ + return !mInputPreeditString.isEmpty(); +} + void SynEdit::collapseAll() { for (int i = mAllFoldRanges.count()-1;i>=0;i--){ @@ -2940,7 +2941,6 @@ void SynEdit::doOnPaintTransient(SynTransientType TransientType) void SynEdit::updateLastCaretX() { - mMBCSStepAside = false; mLastCaretColumn = displayX(); } @@ -4712,17 +4712,15 @@ void SynEdit::moveCaretVert(int DY, bool isSelection) } BufferCoord vDstLineChar = displayToBufferPos(ptDst); int SaveLastCaretX = mLastCaretColumn; - bool NewStepAside = mMBCSStepAside; // set caret and block begin / end incPaintLock(); moveCaretAndSelection(mBlockBegin, vDstLineChar, isSelection); decPaintLock(); - // Set fMBCSStepAside and restore fLastCaretX after moving caret, since + // Restore fLastCaretX after moving caret, since // UpdateLastCaretX, called by SetCaretXYEx, changes them. This is the one // case where we don't want that. - mMBCSStepAside = NewStepAside; mLastCaretColumn = SaveLastCaretX; } diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 24d2029e..5e06f862 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -236,6 +236,8 @@ public: const BufferCoord& ptBefore, const BufferCoord& ptAfter); + bool inputMethodOn(); + void collapseAll(); void unCollpaseAll(); void uncollapseAroundLine(int line); @@ -624,10 +626,7 @@ private: QFont mFontForNonAscii; SynFontSmoothMethod mFontSmoothing; bool mMouseMoved; - /* IME input */ - int mImeCount; - bool mMBCSStepAside; - /* end of IME input */ + bool mInserting; bool mPainting; PSynEditStringList mLines;