Enhance auto-insert

Make auto-insert more usable - no auto-insert if the following (and
previous character - in the case of quote or double quote) character is
not blank character. (fixes #584, fixes #450)
This commit is contained in:
Don Ho 2015-10-06 18:07:30 +02:00
parent 52dda771d3
commit 35adb1910b

View File

@ -498,17 +498,28 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
int caretPos = _pEditView->execute(SCI_GETCURRENTPOS);
char *matchedChars = NULL;
char charPrev = (char)_pEditView->execute(SCI_GETCHARAT, caretPos - 2);
char charNext = (char)_pEditView->execute(SCI_GETCHARAT, caretPos);
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);
// User defined matched pairs should be checked firstly
for (size_t i = 0, len = matchedPairs.size(); i < len; ++i)
{
if (int(matchedPairs[i].first) == character)
{
char userMatchedChar[2] = {'\0', '\0'};
if (isCharNextBlank)
{
char userMatchedChar[2] = { '\0', '\0' };
userMatchedChar[0] = matchedPairs[i].second;
_pEditView->execute(SCI_INSERTTEXT, caretPos, (LPARAM)userMatchedChar);
return;
}
}
}
// if there's no user defined matched pair found, continue to check notepad++'s one
@ -519,26 +530,35 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
{
case int('('):
if (matchedPairConf._doParentheses)
{
if (isCharNextBlank)
{
matchedChars = ")";
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
}
}
break;
case int('['):
if (matchedPairConf._doBrackets)
{
if (isCharNextBlank)
{
matchedChars = "]";
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
}
}
break;
case int('{'):
if (matchedPairConf._doCurlyBrackets)
{
if (isCharNextBlank)
{
matchedChars = "}";
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
}
}
break;
case int('"'):
@ -555,9 +575,12 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
}
}
if (isCharPrevBlank && isCharNextBlank)
{
matchedChars = "\"";
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
}
}
break;
case int('\''):
if (matchedPairConf._doQuotes)
@ -572,9 +595,13 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
return;
}
}
if (isCharPrevBlank && isCharNextBlank)
{
matchedChars = "'";
_insertedMatchedChars.add(MatchedCharInserted(char(character), caretPos - 1));
}
}
break;
case int('>'):