mirror of https://gitlab.com/basile.b/dexed.git
fix more reg in autoindent and auto brace close
This commit is contained in:
parent
e6e0dc6215
commit
17be43d096
|
@ -1692,45 +1692,46 @@ end;
|
||||||
function TDexedMemo.autoIndentationLevel(line: Integer): Integer;
|
function TDexedMemo.autoIndentationLevel(line: Integer): Integer;
|
||||||
var
|
var
|
||||||
leftTokIndex: integer = -1;
|
leftTokIndex: integer = -1;
|
||||||
t: PLexToken = nil;
|
|
||||||
f: PLexToken = nil;
|
f: PLexToken = nil;
|
||||||
i: integer = 0;
|
i: integer = 0;
|
||||||
s: string;
|
s: string;
|
||||||
c: char;
|
c: char;
|
||||||
|
b: integer = 0;
|
||||||
tabCount: integer = 0;
|
tabCount: integer = 0;
|
||||||
spcCount: integer = 0;
|
spcCount: integer = 0;
|
||||||
begin
|
begin
|
||||||
|
result := 0;
|
||||||
|
|
||||||
if not fIsDSource and not alwaysAdvancedFeatures or
|
if not fIsDSource and not alwaysAdvancedFeatures or
|
||||||
not (eoAutoIndent in Options) then
|
not (eoAutoIndent in Options) then
|
||||||
exit(0);
|
exit;
|
||||||
|
|
||||||
leftTokIndex := getIndexOfTokenLeftTo(fLexToks, CaretXY);
|
leftTokIndex := getIndexOfTokenLeftTo(fLexToks, CaretXY);
|
||||||
if (leftTokIndex = -1) or (leftTokIndex >= fLexToks.Count) then
|
if (leftTokIndex = -1) or (leftTokIndex >= fLexToks.Count) then
|
||||||
exit(0);
|
exit;
|
||||||
|
|
||||||
result := 0;
|
// goto previous opened brace
|
||||||
// indent if we're right after an opening brace
|
for i:= leftTokIndex downto 0 do
|
||||||
t := fLexToks[leftTokIndex];
|
|
||||||
result += Byte((t^.kind = ltkSymbol) and (t^.Data[1] = '{'));
|
|
||||||
// goto line beg and look at its indent
|
|
||||||
for i:= leftTokIndex - 1 downto 0 do
|
|
||||||
begin
|
begin
|
||||||
f := fLexToks[i];
|
f := fLexToks[i];
|
||||||
if f^.position.y <> t^.position.y then
|
b += Byte((f^.kind = ltkSymbol) and (f^.Data[1] = '}'));
|
||||||
|
b -= Byte((f^.kind = ltkSymbol) and (f^.Data[1] = '{'));
|
||||||
|
if b = -1 then
|
||||||
break;
|
break;
|
||||||
t := f;
|
|
||||||
end;
|
end;
|
||||||
// add the first token of the line indent
|
// retrieve the indent of the opened brace
|
||||||
if t^.position.x > 0 then
|
if assigned(f) and (f^.position.x > 0) then
|
||||||
begin
|
begin
|
||||||
s := lines[t^.position.y-1][1 .. t^.position.x];
|
s := lines[f^.position.y-1];
|
||||||
for c in s do
|
for c in s do
|
||||||
begin
|
case c of
|
||||||
tabCount += Byte(c = #9);
|
#9: tabCount += 1;
|
||||||
spcCount += Byte(c = ' ');
|
#32:spcCount += 1;
|
||||||
|
else break;
|
||||||
end;
|
end;
|
||||||
result += tabCount + spcCount div TabWidth;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
result += 1 + tabCount + spcCount div TabWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDexedMemo.curlyBraceCloseAndIndent(close: boolean = true);
|
procedure TDexedMemo.curlyBraceCloseAndIndent(close: boolean = true);
|
||||||
|
|
Loading…
Reference in New Issue