mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 13:54:54 +02:00
Enhance auto-insert for parenthesis, bracket and Braces
Enhance auto-insert behaviour for parenthesis, bracket and Braces inside of parenthesis, bracket or Braces.
This commit is contained in:
parent
2c80fc3018
commit
6571731236
@ -504,7 +504,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
|
|||||||
bool isCharPrevBlank = (charPrev == ' ' || charPrev == '\t' || charPrev == '\n' || charPrev == '\r' || charPrev == '\0');
|
bool isCharPrevBlank = (charPrev == ' ' || charPrev == '\t' || charPrev == '\n' || charPrev == '\r' || charPrev == '\0');
|
||||||
int docLen = _pEditView->getCurrentDocLen();
|
int docLen = _pEditView->getCurrentDocLen();
|
||||||
bool isCharNextBlank = (charNext == ' ' || charNext == '\t' || charNext == '\n' || charNext == '\r' || caretPos == docLen);
|
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
|
// User defined matched pairs should be checked firstly
|
||||||
for (size_t i = 0, len = matchedPairs.size(); i < len; ++i)
|
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('('):
|
case int('('):
|
||||||
if (matchedPairConf._doParentheses)
|
if (matchedPairConf._doParentheses)
|
||||||
{
|
{
|
||||||
if (isCharNextBlank)
|
if (isCharNextBlank || isInSandwich)
|
||||||
|
|
||||||
{
|
{
|
||||||
matchedChars = ")";
|
matchedChars = ")";
|
||||||
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
||||||
@ -542,7 +543,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
|
|||||||
case int('['):
|
case int('['):
|
||||||
if (matchedPairConf._doBrackets)
|
if (matchedPairConf._doBrackets)
|
||||||
{
|
{
|
||||||
if (isCharNextBlank)
|
if (isCharNextBlank || isInSandwich)
|
||||||
{
|
{
|
||||||
matchedChars = "]";
|
matchedChars = "]";
|
||||||
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
||||||
@ -553,7 +554,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
|
|||||||
case int('{'):
|
case int('{'):
|
||||||
if (matchedPairConf._doCurlyBrackets)
|
if (matchedPairConf._doCurlyBrackets)
|
||||||
{
|
{
|
||||||
if (isCharNextBlank)
|
if (isCharNextBlank || isInSandwich)
|
||||||
{
|
{
|
||||||
matchedChars = "}";
|
matchedChars = "}";
|
||||||
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
||||||
@ -575,10 +576,10 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((isCharPrevBlank && isCharNextBlank) ||
|
if ((isCharPrevBlank && isCharNextBlank) || isInSandwich ||
|
||||||
(charPrev == '(' && charNext == ')') || (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') ||
|
(charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') ||
|
||||||
(charPrev == '[' && charNext == ']') || (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') ||
|
(charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') ||
|
||||||
(charPrev == '{' && charNext == '}') || (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}'))
|
(charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}'))
|
||||||
{
|
{
|
||||||
matchedChars = "\"";
|
matchedChars = "\"";
|
||||||
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
||||||
@ -599,10 +600,10 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((isCharPrevBlank && isCharNextBlank) ||
|
if ((isCharPrevBlank && isCharNextBlank) || isInSandwich ||
|
||||||
(charPrev == '(' && charNext == ')') || (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') ||
|
(charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') ||
|
||||||
(charPrev == '[' && charNext == ']') || (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') ||
|
(charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']') ||
|
||||||
(charPrev == '{' && charNext == '}') || (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}'))
|
(charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}'))
|
||||||
{
|
{
|
||||||
matchedChars = "'";
|
matchedChars = "'";
|
||||||
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user