From aded956ca806ef7b7ebd3f7b596120c99cde3fb2 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 18 Apr 2023 18:05:27 +0800 Subject: [PATCH] - enhancement: Auto skip ; and , when input. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 39 +++++++++++++++++++++++++++++++++++++++ RedPandaIDE/editor.h | 2 ++ 3 files changed, 42 insertions(+) diff --git a/NEWS.md b/NEWS.md index d6f8b1c7..39f6d5c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ Red Panda C++ Version 2.21 - fix: Project makefile generated for C files is not correct. - fix: Horizontal scroll by touchpad is not working. - fix: Horizontal scroll by touchpad is inversed. + - enhancement: Auto skip ; and , when input. Red Panda C++ Version 2.20 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8b91c7ea..fe32dce5 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1005,6 +1005,8 @@ void Editor::keyPressEvent(QKeyEvent *event) case ']': case '<': case '*': + case ';': + case ',': handled = handleSymbolCompletion(ch); return; case '(': { @@ -2561,6 +2563,20 @@ bool Editor::handleSymbolCompletion(QChar key) return handleGlobalIncludeSkip(); } return false; + case ';': + if (selAvail()) + return false; + if (pSettings->editor().overwriteSymbols()) { + return handleSemiColonSkip(); + } + return false; + case ',': + if (selAvail()) + return false; + if (pSettings->editor().overwriteSymbols()) { + return handlePeriodSkip(); + } + return false; } return false; } @@ -2758,6 +2774,29 @@ bool Editor::handleBraceSkip() return false; } +bool Editor::handleSemiColonSkip() +{ + if (getCurrentChar() != ';') + return false; + bool oldInsertMode = insertMode(); + setInsertMode(false); //set mode to overwrite + processCommand(QSynedit::EditCommand::Char,';'); + setInsertMode(oldInsertMode); + return true; +} + +bool Editor::handlePeriodSkip() +{ + if (getCurrentChar() != ',') + return false; + + bool oldInsertMode = insertMode(); + setInsertMode(false); //set mode to overwrite + processCommand(QSynedit::EditCommand::Char,','); + setInsertMode(oldInsertMode); + return true; +} + bool Editor::handleSingleQuoteCompletion() { QuoteStatus status = getQuoteStatus(); diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index ce8037ab..60baa4bc 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -254,6 +254,8 @@ private: bool handleMultilineCommentCompletion(); bool handleBraceCompletion(); bool handleBraceSkip(); + bool handleSemiColonSkip(); + bool handlePeriodSkip(); bool handleSingleQuoteCompletion(); bool handleDoubleQuoteCompletion(); bool handleGlobalIncludeCompletion();