mirror of https://gitlab.com/basile.b/dexed.git
fix upstram, auto indent broken after ENTER
This commit is contained in:
parent
6a3a49f1f2
commit
2624f049cc
|
@ -148,6 +148,11 @@ function getModuleName(list: TLexTokenList): string;
|
||||||
*)
|
*)
|
||||||
procedure getImports(list: TLexTokenList; imports: TStrings);
|
procedure getImports(list: TLexTokenList; imports: TStrings);
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Get The index of the tokens at the left of the caret position
|
||||||
|
*)
|
||||||
|
function getIndexOfTokenLeftTo(tokens: TLexTokenList; caretPos: TPoint): integer;
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Compares two TPoints.
|
* Compares two TPoints.
|
||||||
*)
|
*)
|
||||||
|
@ -994,6 +999,30 @@ end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
{$REGION Utils}
|
{$REGION Utils}
|
||||||
|
function getIndexOfTokenLeftTo(tokens: TLexTokenList; caretPos: TPoint): integer;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
x: integer;
|
||||||
|
y: integer;
|
||||||
|
t: PLexToken;
|
||||||
|
begin
|
||||||
|
result := -1;
|
||||||
|
for i := tokens.Count-1 downto 0 do
|
||||||
|
begin
|
||||||
|
t := tokens[i];
|
||||||
|
x := caretPos.x;
|
||||||
|
y := caretPos.y;
|
||||||
|
if t^.position.y > y then
|
||||||
|
continue;
|
||||||
|
if ((t^.position.y = y) and (t^.position.x <= x))
|
||||||
|
or (t^.position.y < y) then
|
||||||
|
begin
|
||||||
|
result := i;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TLexErrorList.getError(index: integer): TLexError;
|
function TLexErrorList.getError(index: integer): TLexError;
|
||||||
begin
|
begin
|
||||||
Result := PLexError(Items[index])^;
|
Result := PLexError(Items[index])^;
|
||||||
|
|
|
@ -1692,33 +1692,15 @@ var
|
||||||
i: integer = 0;
|
i: integer = 0;
|
||||||
j: integer = 0;
|
j: integer = 0;
|
||||||
s: integer = $7FFFFFFF;
|
s: integer = $7FFFFFFF;
|
||||||
b: boolean = false;
|
|
||||||
x,y: integer;
|
|
||||||
begin
|
begin
|
||||||
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(0);
|
||||||
|
|
||||||
// locate the token at the left of the caret
|
leftTokIndex := getIndexOfTokenLeftTo(fLexToks, CaretXY);
|
||||||
for i := fLexToks.Count-1 downto 0 do
|
|
||||||
begin
|
|
||||||
t := fLexToks[i];
|
|
||||||
x := CaretX ;
|
|
||||||
y := CaretY ;
|
|
||||||
if fLexToks[i]^.position.y > y then
|
|
||||||
continue;
|
|
||||||
if ((fLexToks[i]^.position.y = y) and (fLexToks[i]^.position.x <= x))
|
|
||||||
or (fLexToks[i]^.position.y < y) then
|
|
||||||
begin
|
|
||||||
leftTokIndex := i;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if leftTokIndex = -1 then
|
if leftTokIndex = -1 then
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
// compute indentation
|
|
||||||
for i := leftTokIndex downto 0 do
|
for i := leftTokIndex downto 0 do
|
||||||
begin
|
begin
|
||||||
t := fLexToks[i];
|
t := fLexToks[i];
|
||||||
|
@ -1727,17 +1709,13 @@ begin
|
||||||
case t^.Data[1] of
|
case t^.Data[1] of
|
||||||
'{':
|
'{':
|
||||||
begin
|
begin
|
||||||
b := true;
|
|
||||||
j += 1;
|
j += 1;
|
||||||
|
if t^.position.x > s then
|
||||||
|
break;
|
||||||
|
s := min(s, t^.position.x);
|
||||||
end;
|
end;
|
||||||
'}': j -= 1;
|
'}': j -= 1;
|
||||||
end;
|
end;
|
||||||
if t^.position.x > s then
|
|
||||||
break;
|
|
||||||
if b then
|
|
||||||
s := min(s, t^.position.x)
|
|
||||||
else
|
|
||||||
s := 0;
|
|
||||||
end;
|
end;
|
||||||
// note: the leftmost openening brace might be on a column <> 0
|
// note: the leftmost openening brace might be on a column <> 0
|
||||||
// but the fix breaks the K&R brace style...
|
// but the fix breaks the K&R brace style...
|
||||||
|
|
Loading…
Reference in New Issue