Merge pull request #4574 from RaiKoHoff/Dev_Master

Enhancement for auto-close char-pairs
This commit is contained in:
Pairi Daiza 2023-02-23 09:27:07 +01:00 committed by GitHub
commit adac8a1e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 9 deletions

View File

@ -8358,23 +8358,39 @@ static void _HandleInsertCheck(const SCNotification* const scn)
}
if (Settings.AutoCloseQuotes) {
if (scn->length == 1) {
bool bInserted = true;
DocPos len = 0;
switch (scn->text[0]) {
case '"':
len = _EncloseSelectionBuffer('"', '"');
if (Sci_GetCurrChar() == '"') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
else {
len = _EncloseSelectionBuffer('"', '"');
}
break;
case '\'':
len = _EncloseSelectionBuffer('\'', '\'');
if (Sci_GetCurrChar() == '\'') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
else {
len = _EncloseSelectionBuffer('\'', '\'');
}
break;
case '`':
len = _EncloseSelectionBuffer('`', '`');
if (Sci_GetCurrChar() == '`') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
else {
len = _EncloseSelectionBuffer('`', '`');
}
break;
default:
bInserted = false;
break;
}
if (bInserted) {
if (len) {
SciCall_ChangeInsertion(len, s_SelectionBuffer);
if (len == 2) {
PostMessage(Globals.hwndEdit, SCI_CHARLEFT, 0, 0);
@ -8384,7 +8400,6 @@ static void _HandleInsertCheck(const SCNotification* const scn)
}
if (Settings.AutoCloseBrackets) {
if (scn->length == 1) {
bool bInserted = true;
DocPos len = 0;
switch (scn->text[0]) {
case '[':
@ -8396,11 +8411,28 @@ static void _HandleInsertCheck(const SCNotification* const scn)
case '(':
len = _EncloseSelectionBuffer('(', ')');
break;
case ')':
if (Sci_GetCurrChar() == ')') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
break;
case '}':
if (Sci_GetCurrChar() == '}') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
break;
case ']':
if (Sci_GetCurrChar() == ']') {
SciCall_ChangeInsertion(0, ""); // clear
PostMessage(Globals.hwndEdit, SCI_CHARRIGHT, 0, 0);
}
break;
default:
bInserted = false;
break;
}
if (bInserted) {
if (len) {
SciCall_ChangeInsertion(len, s_SelectionBuffer);
if (len == 2) {
PostMessage(Globals.hwndEdit, SCI_CHARLEFT, 0, 0);

View File

@ -772,6 +772,9 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool);
#define Sci_GetLineStartPosition(position) SciCall_PositionFromLine(SciCall_LineFromPosition(position))
#define Sci_GetLineEndPosition(position) SciCall_GetLineEndPosition(SciCall_LineFromPosition(position))
#define Sci_GetCurrChar() SciCall_GetCharAt(SciCall_GetCurrentPos())
#define Sci_GetNextChar() SciCall_GetCharAt(SciCall_PositionAfter(SciCall_GetCurrentPos()))
// length of line w/o line-end chars (full use SciCall_LineLength()
#define Sci_GetNetLineLength(line) (SciCall_GetLineEndPosition(line) - SciCall_PositionFromLine(line))