From 9254a13d84f05401901e754df6439c78e9c0b794 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 13 Apr 2022 20:04:10 +0800 Subject: [PATCH] - fix: parenthesis skip doesn't work when editing non-c/c++ files --- NEWS.md | 3 +- RedPandaIDE/editor.cpp | 87 +++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/NEWS.md b/NEWS.md index a5d257e7..af12df1b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,9 +3,10 @@ Red Panda C++ Version 1.0.4 - enhancement: add help link for regular expression in search dialog - enhancement: remember current problem set's filename - enhancement: F1 shorcut opens offcial website - - enhancement: don't auto complete '(', if the next non-space char is neither '(' nor ident char + - enhancement: don't auto complete '(', if the next non-space char is '(' or ident char - enhancement: if a project's unit encoding is the same with project's encoding, don't save its encoding - fix: files will be saved to default encoding inspite of its original encoding + - fix: parenthesis skip doesn't work when editing non-c/c++ files Red Panda C++ Version 1.0.3 - fix: when oj problem grabbed by competitive companion received, diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 411fb73b..e6174f16 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2165,24 +2165,22 @@ bool Editor::handleParentheseSkip() if (status != QuoteStatus::NotQuote) return false; - if (!highlighter()) - return false; if (lines()->count()==0) return false; - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); - if (lastLineState.parenthesisLevel==0) { - setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over - return true; + if (highlighter()) { + SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + if (lastLineState.parenthesisLevel==0) { + setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over + return true; + } + } else { + BufferCoord pos = getMatchingBracket(); + if (pos.Line != 0) { + setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over + return true; + } } return false; -// BufferCoord pos = getMatchingBracket(); -// if (pos.Line != 0) { -// setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over -// return true; -// } -// if FunctionTipAllowed then - // fFunctionTip.Activated := false; -// return false; } bool Editor::handleBracketCompletion() @@ -2217,20 +2215,22 @@ bool Editor::handleBracketSkip() { if (getCurrentChar() != ']') return false; - if (!highlighter()) - return false; + if (lines()->count()==0) return false; - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); - if (lastLineState.bracketLevel==0) { - setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over - return true; + if (highlighter()) { + SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + if (lastLineState.bracketLevel==0) { + setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over + return true; + } + } else { + BufferCoord pos = getMatchingBracket(); + if (pos.Line != 0) { + setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over + return true; + } } -// BufferCoord pos = getMatchingBracket(); -// if (pos.Line != 0) { -// setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over -// return true; -// } return false; } @@ -2301,27 +2301,28 @@ bool Editor::handleBraceSkip() { if (getCurrentChar() != '}') return false; - if (!highlighter()) - return false; + if (lines()->count()==0) return false; - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); - if (lastLineState.braceLevel==0) { - bool oldInsertMode = insertMode(); - setInsertMode(false); //set mode to overwrite - commandProcessor(SynEditorCommand::ecChar,'}'); - setInsertMode(oldInsertMode); - return true; + if (highlighter()) { + SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + if (lastLineState.braceLevel==0) { + bool oldInsertMode = insertMode(); + setInsertMode(false); //set mode to overwrite + commandProcessor(SynEditorCommand::ecChar,'}'); + setInsertMode(oldInsertMode); + return true; + } + } else { + BufferCoord pos = getMatchingBracket(); + if (pos.Line != 0) { + bool oldInsertMode = insertMode(); + setInsertMode(false); //set mode to overwrite + commandProcessor(SynEditorCommand::ecChar,'}'); + setInsertMode(oldInsertMode); + return true; + } } -// BufferCoord pos = getMatchingBracket(); -// if (pos.Line != 0) { -// bool oldInsertMode = insertMode(); -// setInsertMode(false); //set mode to overwrite -// commandProcessor(SynEditorCommand::ecChar,'}'); -// setInsertMode(oldInsertMode); -//// setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over -// return true; -// } return false; }