mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 11:59:08 +02:00
SynEdit: Fix TSynAutoComplete. Issue #30187
- ecDeleteLastChar would not work for utf-8, - and also not if it did "reverse tab" based on gaps of the line above (Indenter). - It also wrongly assumed that there would always be an indent and it would be of spaces and spaces only.
This commit is contained in:
parent
e763d920b7
commit
6a84f7039d
@ -2066,42 +2066,62 @@ end;
|
|||||||
|
|
||||||
procedure TSynAutoComplete.Execute(token: string; aEditor: TCustomSynEdit);
|
procedure TSynAutoComplete.Execute(token: string; aEditor: TCustomSynEdit);
|
||||||
var
|
var
|
||||||
Temp: string;
|
LeadSpaces, NewText, Temp: string;
|
||||||
i, j, prevspace: integer;
|
TkIdx, j, FirstIdx: integer;
|
||||||
StartOfBlock: tpoint;
|
StartOfBlock, p1, p2, p3: tpoint;
|
||||||
|
DelPos: SizeInt;
|
||||||
begin
|
begin
|
||||||
//Writeln('[TSynAutoComplete.Execute] Token is "',Token,'"');
|
//Writeln('[TSynAutoComplete.Execute] Token is "',Token,'"');
|
||||||
i := AutoCompleteList.IndexOf(token);
|
TkIdx := AutoCompleteList.IndexOf(token);
|
||||||
if i <> -1 then begin
|
if TkIdx <> -1 then begin
|
||||||
for j := 1 to length(token) do
|
// Get the start of the token that will be replaced
|
||||||
aEditor.CommandProcessor(ecDeleteLastChar, ' ', nil);
|
p1 := aEditor.LogicalCaretXY;
|
||||||
inc(i);
|
p1.X := p1.X - Length(token);
|
||||||
|
|
||||||
|
// Get the spaces prefix for new lines
|
||||||
|
aEditor.CommandProcessor(ecLineBreak, ' ', nil);
|
||||||
|
LeadSpaces := '';
|
||||||
|
p2 := aEditor.LogicalCaretXY;
|
||||||
|
if p2.X > 1 then begin
|
||||||
|
p3 := p2;
|
||||||
|
p3.x := 1;
|
||||||
|
LeadSpaces := aEditor.TextBetweenPoints[p3, p2];
|
||||||
|
end;
|
||||||
|
|
||||||
|
inc(TkIdx);
|
||||||
|
FirstIdx := TkIdx;
|
||||||
|
DelPos := -1;
|
||||||
StartOfBlock := Point(-1, -1);
|
StartOfBlock := Point(-1, -1);
|
||||||
PrevSpace := 0;
|
NewText := '';
|
||||||
while (i < AutoCompleteList.Count) and
|
while (TkIdx < AutoCompleteList.Count) and
|
||||||
(length(AutoCompleteList[i]) > 0) and
|
(length(AutoCompleteList[TkIdx]) > 0) and
|
||||||
(AutoCompleteList[i][1] = '=') do begin
|
(AutoCompleteList[TkIdx][1] = '=')
|
||||||
for j := 0 to PrevSpace - 1 do
|
do begin
|
||||||
aEditor.CommandProcessor(ecDeleteLastChar, ' ', nil);
|
if TkIdx > FirstIdx then
|
||||||
Temp := AutoCompleteList[i];
|
NewText := NewText + LineEnding + LeadSpaces;
|
||||||
PrevSpace := 0;
|
|
||||||
while (length(temp) >= PrevSpace + 2) and (temp[PrevSpace + 2] <= ' ') do
|
Temp := AutoCompleteList[TkIdx];
|
||||||
inc(PrevSpace);
|
delete(Temp, 1, 1);
|
||||||
for j := 2 to length(Temp) do begin
|
|
||||||
aEditor.CommandProcessor(ecChar, Temp[j], nil);
|
j := Pos('|', Temp);
|
||||||
if Temp[j] = '|' then
|
if j > 0 then begin
|
||||||
StartOfBlock := aEditor.CaretXY
|
DelPos := Length(NewText) + j;
|
||||||
|
if FirstIdx = TkIdx then
|
||||||
|
StartOfBlock := Point(p1.X + j - 1, p1.Y + TkIdx - FirstIdx)
|
||||||
|
else
|
||||||
|
StartOfBlock := Point(p2.X + j - 1, p1.Y + TkIdx - FirstIdx);
|
||||||
end;
|
end;
|
||||||
inc(i);
|
|
||||||
if (i < AutoCompleteList.Count) and
|
NewText := NewText + Temp;
|
||||||
(length(AutoCompleteList[i]) > 0) and
|
inc(TkIdx);
|
||||||
(AutoCompleteList[i][1] = '=') then
|
|
||||||
aEditor.CommandProcessor(ecLineBreak, ' ', nil);
|
|
||||||
end;
|
end;
|
||||||
if (StartOfBlock.x <> -1) and (StartOfBlock.y <> -1) then begin
|
|
||||||
|
if DelPos > 0 then
|
||||||
|
Delete(NewText, DelPos, 1);
|
||||||
|
aEditor.TextBetweenPointsEx[p1, p2, scamEnd] := NewText;
|
||||||
|
|
||||||
|
if (StartOfBlock.x <> -1) and (StartOfBlock.y <> -1) then
|
||||||
aEditor.CaretXY := StartOfBlock;
|
aEditor.CaretXY := StartOfBlock;
|
||||||
aEditor.CommandProcessor(ecDeleteLastChar, ' ', nil);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user