From 65717312369588cbe2bfe356e912ae36645d76b3 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 14 Oct 2015 20:38:12 +0200 Subject: [PATCH] Enhance auto-insert for parenthesis, bracket and Braces Enhance auto-insert behaviour for parenthesis, bracket and Braces inside of parenthesis, bracket or Braces. --- .../src/ScitillaComponent/AutoCompletion.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp index d687e5afb..112002cad 100644 --- a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp @@ -504,7 +504,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m bool isCharPrevBlank = (charPrev == ' ' || charPrev == '\t' || charPrev == '\n' || charPrev == '\r' || charPrev == '\0'); int docLen = _pEditView->getCurrentDocLen(); bool isCharNextBlank = (charNext == ' ' || charNext == '\t' || charNext == '\n' || charNext == '\r' || caretPos == docLen); - + bool isInSandwich = (charPrev == '(' && charNext == ')') || (charPrev == '[' && charNext == ']') || (charPrev == '{' && charNext == '}'); // User defined matched pairs should be checked firstly for (size_t i = 0, len = matchedPairs.size(); i < len; ++i) @@ -531,7 +531,8 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m case int('('): if (matchedPairConf._doParentheses) { - if (isCharNextBlank) + if (isCharNextBlank || isInSandwich) + { matchedChars = ")"; _insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1)); @@ -542,7 +543,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m case int('['): if (matchedPairConf._doBrackets) { - if (isCharNextBlank) + if (isCharNextBlank || isInSandwich) { matchedChars = "]"; _insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1)); @@ -553,7 +554,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m case int('{'): if (matchedPairConf._doCurlyBrackets) { - if (isCharNextBlank) + if (isCharNextBlank || isInSandwich) { matchedChars = "}"; _insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1)); @@ -575,10 +576,10 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m } } - if ((isCharPrevBlank && isCharNextBlank) || - (charPrev == '(' && charNext == ')') || (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') || - (charPrev == '[' && charNext == ']') || (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') || - (charPrev == '{' && charNext == '}') || (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}')) + if ((isCharPrevBlank && isCharNextBlank) || isInSandwich || + (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') || + (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') || + (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}')) { matchedChars = "\""; _insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1)); @@ -599,10 +600,10 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m } } - if ((isCharPrevBlank && isCharNextBlank) || - (charPrev == '(' && charNext == ')') || (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') || - (charPrev == '[' && charNext == ']') || (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') || - (charPrev == '{' && charNext == '}') || (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}')) + if ((isCharPrevBlank && isCharNextBlank) || isInSandwich || + (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') || + (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') || + (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}')) { matchedChars = "'"; _insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));