From 87586202dc4be3152c4ea6bec0a77d53cc7fd14d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 12 Apr 2024 12:54:12 +0800 Subject: [PATCH] - fix: Toggle breakpoint by shortcut may use wrong line. --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 39 +++++++--------------- RedPandaIDE/mainwindow.h | 1 - RedPandaIDE/widgets/searchdialog.cpp | 13 +++++--- RedPandaIDE/widgets/searchinfiledialog.cpp | 5 +-- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/NEWS.md b/NEWS.md index 87163d81..34396870 100644 --- a/NEWS.md +++ b/NEWS.md @@ -136,6 +136,7 @@ Red Panda C++ Version 2.27 - enhancement: In debug console, Ctrl+C/Ctrl+X/Ctrl+V conflicts with application action. - enhancement: Auto hide Edit/Selection/Code/Refactor menu if no file openning. - enhancement: Auto hide Project menu if no project openning. + - fix: Toggle breakpoint by shortcut may use wrong line. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index e8f2bca0..1de521ea 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -5149,12 +5149,10 @@ void MainWindow::onEditorContextMenu(const QPoint& pos) ); QMenu menu(this); QSynedit::BufferCoord p; - mEditorContextMenuPos = pos; int line; if (editor->getPositionOfMouse(p)) { line=p.line; if (!switchHeaderSourceTarget(editor).isEmpty()) { - menu.addAction(ui->actionSwitchHeaderSource); menu.addSeparator(); } @@ -6322,16 +6320,6 @@ void MainWindow::on_actionPaste_triggered() editor->pasteFromClipboard(); editor->activate(); } - } else if (data->hasUrls()) { - QStringList filesToOpen; - foreach (const QUrl& url, data->urls()) { - QString s = url.toLocalFile(); - if (!s.isEmpty()) { - filesToOpen.append(s); - } - } - if (!filesToOpen.isEmpty()) - openFiles(filesToOpen); } } @@ -6949,9 +6937,8 @@ void MainWindow::on_actionPrevious_Editor_triggered() void MainWindow::on_actionToggle_Breakpoint_triggered() { Editor * editor = mEditorList->getEditor(); - int line; - if (editor && editor->pointToLine(mEditorContextMenuPos,line)) - editor->toggleBreakpoint(line); + if (editor) + editor->toggleBreakpoint(editor->caretY()); } @@ -6973,12 +6960,11 @@ void MainWindow::on_actionClear_all_breakpoints_triggered() void MainWindow::on_actionBreakpoint_property_triggered() { Editor * editor = mEditorList->getEditor(); - int line; - if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { + if (editor) { + int line = editor->caretY(); if (editor->hasBreakpoint(line)) editor->modifyBreakpointProperty(line); } - } @@ -7002,10 +6988,9 @@ void MainWindow::on_actionGoto_Definition_triggered() void MainWindow::on_actionFind_references_triggered() { Editor * editor = mEditorList->getEditor(); - QSynedit::BufferCoord pos; - if (editor && editor->pointToCharLine(mEditorContextMenuPos,pos)) { + if (editor) { CppRefacter refactor; - refactor.findOccurence(editor,pos); + refactor.findOccurence(editor, editor->caretXY()); showSearchPanel(false); } } @@ -8587,10 +8572,10 @@ TodoModel *MainWindow::todoModel() void MainWindow::on_actionAdd_bookmark_triggered() { Editor* editor = mEditorList->getEditor(); - int line; - if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { + if (editor) { if (editor->lineCount()<=0) return; + int line = editor->caretY(); QString desc = QInputDialog::getText(editor,tr("Bookmark Description"), tr("Description:"),QLineEdit::Normal, editor->lineText(line).trimmed()); @@ -8604,8 +8589,8 @@ void MainWindow::on_actionAdd_bookmark_triggered() void MainWindow::on_actionRemove_Bookmark_triggered() { Editor* editor = mEditorList->getEditor(); - int line; - if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { + if (editor) { + int line = editor->caretY(); editor->removeBookmark(line); mBookmarkModel->removeBookmark(editor->filename(),line,editor->inProject()); } @@ -8629,8 +8614,8 @@ void MainWindow::on_tableBookmark_doubleClicked(const QModelIndex &index) void MainWindow::on_actionModify_Bookmark_Description_triggered() { Editor* editor = mEditorList->getEditor(); - int line; - if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { + if (editor) { + int line = editor->caretY(); PBookmark bookmark = mBookmarkModel->bookmark(editor->filename(),line); if (bookmark) { QString desc = QInputDialog::getText(editor,tr("Bookmark Description"), diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9b5e58b6..6a722475 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -932,7 +932,6 @@ private: bool mClosingAll; bool mOpenningFiles; bool mSystemTurnedOff; - QPoint mEditorContextMenuPos; QTcpServer mTcpServer; QColor mErrorColor; CompileIssuesState mCompileIssuesState; diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index 698b4b65..d4182dd3 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -42,17 +42,20 @@ SearchDialog::~SearchDialog() void SearchDialog::find(const QString &text) { mTabBar->setCurrentIndex(mSearchTabIdx); - ui->cbFind->setCurrentText(text); - ui->cbFind->setFocus(); + if (!text.isEmpty()) + ui->cbFind->setCurrentText(text); + ui->btnNext->setFocus(); show(); } void SearchDialog::replace(const QString &text) { mTabBar->setCurrentIndex(mReplaceTabIdx); - ui->cbFind->setCurrentText(text); - ui->cbReplace->setCurrentText(text); - ui->cbFind->setFocus(); + if (!text.isEmpty()) { + ui->cbFind->setCurrentText(text); + ui->cbReplace->setCurrentText(text); + } + ui->btnNext->setFocus(); show(); } diff --git a/RedPandaIDE/widgets/searchinfiledialog.cpp b/RedPandaIDE/widgets/searchinfiledialog.cpp index 4fa7df66..5e69b7c8 100644 --- a/RedPandaIDE/widgets/searchinfiledialog.cpp +++ b/RedPandaIDE/widgets/searchinfiledialog.cpp @@ -54,8 +54,9 @@ SearchInFileDialog::~SearchInFileDialog() void SearchInFileDialog::findInFiles(const QString &text) { - ui->cbFind->setCurrentText(text); - ui->cbFind->setFocus(); + if (!text.isEmpty()) + ui->cbFind->setCurrentText(text); + ui->btnExecute->setFocus(); show(); }