mirror of https://gitlab.com/basile.b/dexed.git
use a simpler logic to compute indent on LF
This commit is contained in:
parent
d14afe5e1d
commit
b140ac1c84
|
@ -1563,7 +1563,10 @@ begin
|
||||||
showCallTips(true);
|
showCallTips(true);
|
||||||
end;
|
end;
|
||||||
ecCurlyBraceClose:
|
ecCurlyBraceClose:
|
||||||
|
begin
|
||||||
|
lexWholeText([TLexOption.lxoNoWhites, TLexOption.lxoNoComments]);
|
||||||
curlyBraceCloseAndIndent;
|
curlyBraceCloseAndIndent;
|
||||||
|
end;
|
||||||
ecCommentSelection:
|
ecCommentSelection:
|
||||||
commentSelection;
|
commentSelection;
|
||||||
ecSwapVersionAllNone:
|
ecSwapVersionAllNone:
|
||||||
|
@ -1689,37 +1692,44 @@ function TDexedMemo.autoIndentationLevel(line: Integer): Integer;
|
||||||
var
|
var
|
||||||
leftTokIndex: integer = -1;
|
leftTokIndex: integer = -1;
|
||||||
t: PLexToken = nil;
|
t: PLexToken = nil;
|
||||||
|
f: PLexToken = nil;
|
||||||
i: integer = 0;
|
i: integer = 0;
|
||||||
j: integer = 0;
|
s: string;
|
||||||
s: integer = $7FFFFFFF;
|
c: char;
|
||||||
|
tabCount: integer = 0;
|
||||||
|
spcCount: integer = 0;
|
||||||
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);
|
||||||
|
|
||||||
leftTokIndex := getIndexOfTokenLeftTo(fLexToks, CaretXY);
|
leftTokIndex := getIndexOfTokenLeftTo(fLexToks, CaretXY);
|
||||||
if leftTokIndex = -1 then
|
if (leftTokIndex = -1) or (leftTokIndex >= fLexToks.Count) then
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
for i := leftTokIndex downto 0 do
|
result := 0;
|
||||||
|
// indent if we're right after an opening brace
|
||||||
|
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
|
||||||
t := fLexToks[i];
|
f := fLexToks[i];
|
||||||
if t^.kind <> ltkSymbol then
|
if f^.position.y <> t^.position.y then
|
||||||
continue;
|
break;
|
||||||
case t^.Data[1] of
|
t := f;
|
||||||
'{':
|
end;
|
||||||
begin
|
// add the first token of the line indent
|
||||||
j += 1;
|
if t^.position.x > 0 then
|
||||||
if t^.position.x > s then
|
begin
|
||||||
break;
|
s := LineText[1 .. t^.position.x];
|
||||||
s := min(s, t^.position.x);
|
for c in s do
|
||||||
end;
|
begin
|
||||||
'}': j -= 1;
|
tabCount += Byte(c = #9);
|
||||||
end;
|
spcCount += Byte(c = ' ');
|
||||||
|
end;
|
||||||
|
result += tabCount + spcCount div TabWidth;
|
||||||
end;
|
end;
|
||||||
// note: the leftmost openening brace might be on a column <> 0
|
|
||||||
// but the fix breaks the K&R brace style...
|
|
||||||
result := j ;//+ (s div TabWidth);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDexedMemo.curlyBraceCloseAndIndent(close: boolean = true);
|
procedure TDexedMemo.curlyBraceCloseAndIndent(close: boolean = true);
|
||||||
|
@ -3522,7 +3532,7 @@ begin
|
||||||
if ((LogicalCaretXY.X - 1 >= line.length) or
|
if ((LogicalCaretXY.X - 1 >= line.length) or
|
||||||
isBlank(line[LogicalCaretXY.X .. line.length])) then
|
isBlank(line[LogicalCaretXY.X .. line.length])) then
|
||||||
begin
|
begin
|
||||||
lexWholeText();
|
lexWholeText([TLexOption.lxoNoWhites, TLexOption.lxoNoComments]);
|
||||||
lxd := true;
|
lxd := true;
|
||||||
ccb := lexCanCloseBrace;
|
ccb := lexCanCloseBrace;
|
||||||
if ccb <> braceCloseInvalid then
|
if ccb <> braceCloseInvalid then
|
||||||
|
@ -3629,7 +3639,7 @@ begin
|
||||||
'{': if (fAutoCloseCurlyBrace = autoCloseLexically) and
|
'{': if (fAutoCloseCurlyBrace = autoCloseLexically) and
|
||||||
(GetKeyShiftState <> [ssShift]) then
|
(GetKeyShiftState <> [ssShift]) then
|
||||||
begin
|
begin
|
||||||
lexWholeText();
|
lexWholeText([TLexOption.lxoNoWhites, TLexOption.lxoNoComments]);
|
||||||
case lexCanCloseBrace of
|
case lexCanCloseBrace of
|
||||||
braceClosePositive: curlyBraceCloseAndIndent;
|
braceClosePositive: curlyBraceCloseAndIndent;
|
||||||
braceCloseLessEven: curlyBraceCloseAndIndent(false);
|
braceCloseLessEven: curlyBraceCloseAndIndent(false);
|
||||||
|
|
Loading…
Reference in New Issue