mirror of https://gitlab.com/basile.b/dexed.git
rewrite auto-closing, get indentation from the previous non blank line
This commit is contained in:
parent
87905802d1
commit
b17c58d924
|
@ -771,54 +771,49 @@ end;
|
||||||
|
|
||||||
procedure curlyBraceCloseAndIndent(editor: TSynEdit);
|
procedure curlyBraceCloseAndIndent(editor: TSynEdit);
|
||||||
var
|
var
|
||||||
beg: string;
|
i: integer;
|
||||||
i: integer = 1;
|
beg: string = '';
|
||||||
j: integer;
|
numTabs: integer = 0;
|
||||||
const
|
numSpac: integer = 0;
|
||||||
blk = [' ', #9];
|
|
||||||
begin
|
begin
|
||||||
beg := editor.LineText;
|
|
||||||
if beg.isEmpty then exit;
|
i := editor.CaretY - 1;
|
||||||
beg := beg[1..editor.CaretX];
|
|
||||||
if beg.isEmpty then exit;
|
|
||||||
while true do
|
while true do
|
||||||
begin
|
begin
|
||||||
if (i > beg.length) or not (beg[i] in blk) then
|
if i < 0 then
|
||||||
break;
|
break;
|
||||||
i += 1;
|
beg := editor.Lines[i];
|
||||||
end;
|
if beg.isBlank then
|
||||||
if (beg[i] <> '{') and (i > 1) then
|
i -= 1
|
||||||
begin
|
|
||||||
if (eoTabsToSpaces in editor.Options) then
|
|
||||||
i -= editor.TabWidth
|
|
||||||
else
|
else
|
||||||
i -= 1;
|
break;
|
||||||
end;
|
end;
|
||||||
i -= 1;
|
|
||||||
|
for i:= 1 to beg.length do
|
||||||
|
begin
|
||||||
|
case beg[i] of
|
||||||
|
#9: numTabs += 1;
|
||||||
|
' ': numSpac += 1;
|
||||||
|
else break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
numTabs += numSpac div editor.TabWidth;
|
||||||
|
|
||||||
editor.BeginUndoBlock;
|
editor.BeginUndoBlock;
|
||||||
|
|
||||||
editor.CommandProcessor(ecInsertLine, '', nil);
|
editor.CommandProcessor(ecInsertLine, '', nil);
|
||||||
editor.CommandProcessor(ecDown, '', nil);
|
editor.CommandProcessor(ecDown, '', nil);
|
||||||
|
|
||||||
editor.CommandProcessor(ecInsertLine, '', nil);
|
editor.CommandProcessor(ecInsertLine, '', nil);
|
||||||
editor.CommandProcessor(ecDown, '', nil);
|
editor.CommandProcessor(ecDown, '', nil);
|
||||||
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
||||||
for j := 1 to i do
|
for i:= 0 to numTabs-1 do editor.CommandProcessor(ecTab, '', nil);
|
||||||
begin
|
|
||||||
if beg[j] = #9 then
|
|
||||||
editor.CommandProcessor(ecTab, '', nil)
|
|
||||||
else
|
|
||||||
editor.CommandProcessor(ecChar, beg[j], nil);
|
|
||||||
end;
|
|
||||||
editor.CommandProcessor(ecChar, '}', nil);
|
editor.CommandProcessor(ecChar, '}', nil);
|
||||||
|
|
||||||
editor.CommandProcessor(ecUp, '', nil);
|
editor.CommandProcessor(ecUp, '', nil);
|
||||||
for j := 1 to i do
|
while editor.CaretX <> 1 do editor.CommandProcessor(ecLeft, '' , nil);
|
||||||
begin
|
for i:= 0 to numTabs do editor.CommandProcessor(ecTab, '', nil);
|
||||||
if beg[j] = #9 then
|
|
||||||
editor.CommandProcessor(ecTab, '', nil)
|
|
||||||
else
|
|
||||||
editor.CommandProcessor(ecChar, beg[j], nil);
|
|
||||||
end;
|
|
||||||
editor.CommandProcessor(ecTab, '', nil);
|
|
||||||
while editor.LogicalCaretXY.X > 1 + i + editor.TabWidth do editor.CommandProcessor(ecLeft, '' , nil);
|
|
||||||
editor.EndUndoBlock;
|
editor.EndUndoBlock;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1446,7 +1441,7 @@ begin
|
||||||
Key := 0;
|
Key := 0;
|
||||||
curlyBraceCloseAndIndent(self);
|
curlyBraceCloseAndIndent(self);
|
||||||
end;
|
end;
|
||||||
autoCloseOnNewLineLexically:
|
autoCloseOnNewLineLexically: if LogicalCaretXY.X - 1 >= lineText.length then
|
||||||
begin
|
begin
|
||||||
fLexToks.Clear;
|
fLexToks.Clear;
|
||||||
lex(lines.Text, fLexToks);
|
lex(lines.Text, fLexToks);
|
||||||
|
|
Loading…
Reference in New Issue