diff --git a/NEWS.md b/NEWS.md index 31f4e808..125ceb0a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ Red Panda C++ Version 1.0.0 - enhancement: auto detect "gbk" encoding when running in zh_CN locale under Linux - enhancement: disable encoding submenu when editor closed - enhancement: clear infos in the status bar when editor closed + - fix: wrong selection when drag & dropped in editor Red Panda C++ Version 0.14.5 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 77c8136b..6cfc2f56 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -7121,3 +7121,12 @@ void MainWindow::on_actionFilesView_Hide_Non_Support_Files_toggled(bool /* arg1 } } + +void MainWindow::on_actionToggle_Block_Comment_triggered() +{ + Editor * editor = mEditorList->getEditor(); + if (editor != NULL ) { + editor->toggleBlockComment(); + } +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index d92d1f1a..c5e904d1 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -607,6 +607,8 @@ private slots: void on_actionFilesView_Hide_Non_Support_Files_toggled(bool arg1); + void on_actionToggle_Block_Comment_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 94094a1c..d5dd495e 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -1489,6 +1489,7 @@ + @@ -2851,6 +2852,14 @@ Hide Non Support Files + + + Toggle Block Comment + + + Alt+Shift+A + + diff --git a/RedPandaIDE/qsynedit/KeyStrokes.h b/RedPandaIDE/qsynedit/KeyStrokes.h index 4e8d4bda..ad19bc14 100644 --- a/RedPandaIDE/qsynedit/KeyStrokes.h +++ b/RedPandaIDE/qsynedit/KeyStrokes.h @@ -162,7 +162,7 @@ enum class SynEditorCommand { ecComment = 614, ecUncomment = 615, ecToggleComment = 616, - ecCommentInline = 617, + ecToggleBlockComment = 617, ecUpperCase = 620, // apply to the current or previous word ecLowerCase = 621, diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 73b88671..e83a4075 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -39,7 +39,8 @@ #include #include -SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) +SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), + mDropped(false) { mLastKey = 0; mLastKeyModifiers = Qt::NoModifier; @@ -1789,8 +1790,38 @@ void SynEdit::doToggleComment() doComment(); } +void SynEdit::doToggleBlockComment() +{ + QString s; + if (mReadOnly) + return; + doOnPaintTransient(SynTransientType::ttBefore); + + QString text=selText().trimmed(); + if (text.length()>4 && text.startsWith("/*") && text.endsWith("*/")) { + QString newText=selText(); + int pos = newText.indexOf("/*"); + if (pos>=0) { + newText.remove(pos,2); + } + pos = newText.lastIndexOf("*/"); + if (pos>=0) { + newText.remove(pos,2); + } + setSelText(newText); + } else { + QString newText="/*"+selText()+"*/"; + setSelText(newText); + } + +} + void SynEdit::doMouseScroll(bool isDragging) { + if (mDropped) { + mDropped=false; + return; + } QPoint iMousePos; DisplayCoord C; int X, Y; @@ -5643,6 +5674,9 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData) case SynEditorCommand::ecToggleComment: doToggleComment(); break; + case SynEditorCommand::ecToggleBlockComment: + doToggleBlockComment(); + break; case SynEditorCommand::ecNormalSelect: setSelectionMode(SynSelectionMode::smNormal); break; @@ -6148,9 +6182,8 @@ void SynEdit::dropEvent(QDropEvent *event) } mUndoList->EndBlock(); } - event->acceptProposedAction(); - + mDropped = true; } void SynEdit::dragMoveEvent(QDragMoveEvent *event) diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 5e06f862..fff08f45 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -276,6 +276,7 @@ public: virtual void tab() { commandProcessor(SynEditorCommand::ecTab);} virtual void shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);} virtual void toggleComment() { commandProcessor(SynEditorCommand::ecToggleComment);} + virtual void toggleBlockComment() { commandProcessor(SynEditorCommand::ecToggleBlockComment);} virtual void beginUpdate(); virtual void endUpdate(); @@ -589,6 +590,7 @@ private: void doComment(); void doUncomment(); void doToggleComment(); + void doToggleBlockComment(); void doMouseScroll(bool isDragging); @@ -729,7 +731,7 @@ private: BufferCoord mDragCaretSave; BufferCoord mDragSelBeginSave; BufferCoord mDragSelEndSave; - bool mDragging; + bool mDropped; friend class SynEditTextPainter;