improve curly brace auto-closing and support CTRL to skip auto closing, clsoe #342

This commit is contained in:
Basile Burg 2018-07-03 13:44:36 +02:00
parent e4fd4d7672
commit ef2ca016ff
1 changed files with 50 additions and 38 deletions

View File

@ -1591,6 +1591,7 @@ var
beg: string = ''; beg: string = '';
numTabs: integer = 0; numTabs: integer = 0;
numSpac: integer = 0; numSpac: integer = 0;
numSkip: integer = 0;
begin begin
if not fIsDSource and not alwaysAdvancedFeatures then if not fIsDSource and not alwaysAdvancedFeatures then
exit; exit;
@ -1601,10 +1602,18 @@ begin
if i < 0 then if i < 0 then
break; break;
beg := Lines[i]; beg := Lines[i];
if (Pos('{', beg) = 0) then if (Pos('}', beg) <> 0) then
i -= 1 begin
numSkip += 1;
end
else if (Pos('{', beg) <> 0) then
begin
numSkip -= 1;
end;
if numSkip < 0 then
break
else else
break; i -= 1;
end; end;
for i:= 1 to beg.length do for i:= 1 to beg.length do
@ -3337,55 +3346,58 @@ begin
begin begin
fCanDscan:=true; fCanDscan:=true;
line := LineText; line := LineText;
case fAutoCloseCurlyBrace of if [ssCtrl] <> Shift then
autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
begin
Key := 0;
curlyBraceCloseAndIndent;
end;
autoCloseOnNewLineEof: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
if (CaretY = Lines.Count) and (CaretX = line.length+1) then
begin
Key := 0;
curlyBraceCloseAndIndent;
end;
end;
if (fAutoCloseCurlyBrace = autoCloseOnNewLineLexically) or
fSmartDdocNewline then
begin begin
lxd := false; case fAutoCloseCurlyBrace of
if (LogicalCaretXY.X - 1 >= line.length) autoCloseOnNewLineAlways: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
or isBlank(line[LogicalCaretXY.X .. line.length]) then begin
begin Key := 0;
lxd := true; curlyBraceCloseAndIndent;
fLexToks.Clear; end;
lex(lines.Text, fLexToks); autoCloseOnNewLineEof: if (CaretX > 1) and (line[LogicalCaretXY.X - 1] = '{') then
if lexCanCloseBrace then if (CaretY = Lines.Count) and (CaretX = line.length+1) then
begin begin
Key := 0; Key := 0;
curlyBraceCloseAndIndent; curlyBraceCloseAndIndent;
lxd := false;
end; end;
end; end;
if (fSmartDdocNewline) then if (fAutoCloseCurlyBrace = autoCloseOnNewLineLexically) or
fSmartDdocNewline then
begin begin
if not lxd then lxd := false;
if (LogicalCaretXY.X - 1 >= line.length)
or isBlank(line[LogicalCaretXY.X .. line.length]) then
begin begin
lxd := true;
fLexToks.Clear; fLexToks.Clear;
lex(lines.Text, fLexToks); lex(lines.Text, fLexToks);
if lexCanCloseBrace then
begin
Key := 0;
curlyBraceCloseAndIndent;
lxd := false;
end;
end; end;
ddc := lexInDdoc; if (fSmartDdocNewline) then
if ddc in ['*', '+'] then
begin begin
inherited; if not lxd then
insertLeadingDDocSymbol(ddc); begin
fCanShowHint:=false; fLexToks.Clear;
fDDocWin.Hide; lex(lines.Text, fLexToks);
exit; end;
ddc := lexInDdoc;
if ddc in ['*', '+'] then
begin
inherited;
insertLeadingDDocSymbol(ddc);
fCanShowHint:=false;
fDDocWin.Hide;
exit;
end;
end; end;
end; end;
end; end
else shift := [];
end; end;
end; end;
inherited; inherited;