mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-20 19:39:29 +01:00
cody: insert call inherited: improved cursor
git-svn-id: trunk@34227 -
This commit is contained in:
parent
9bf66b8e04
commit
5ab530a8e7
@ -80,7 +80,7 @@ function InEmptyLine(const ASource: string; StartPos: integer): boolean;
|
||||
function GetLineIndent(const Source: string; Position: integer): integer;
|
||||
function GetLineIndentWithTabs(const Source: string; Position: integer;
|
||||
TabWidth: integer): integer;
|
||||
function GetPosInLine(const Source: string; Position: integer): integer;
|
||||
function GetPosInLine(const Source: string; Position: integer): integer; // 0 based
|
||||
function GetBlockMinIndent(const Source: string;
|
||||
StartPos, EndPos: integer): integer;
|
||||
function GetIndentStr(Indent: integer): string;
|
||||
@ -4014,7 +4014,7 @@ end;
|
||||
function GetPosInLine(const Source: string; Position: integer): integer;
|
||||
begin
|
||||
Result:=0;
|
||||
while (Position>1) and (not (Source[Position] in [#10,#13])) do begin
|
||||
while (Position>1) and (not (Source[Position-1] in [#10,#13])) do begin
|
||||
inc(Result);
|
||||
dec(Position);
|
||||
end;
|
||||
|
||||
@ -220,6 +220,9 @@ var
|
||||
NewIndent: TFABIndentationPolicy;
|
||||
NewLine: Boolean;
|
||||
Gap: TGapTyp;
|
||||
FromPos: Integer;
|
||||
ToPos: Integer;
|
||||
NewXY: TPoint;
|
||||
begin
|
||||
if (ParseTilCursor(Tool,CleanPos,CursorNode,Handled,true)<>cupeSuccess)
|
||||
and not Handled then begin
|
||||
@ -256,7 +259,10 @@ begin
|
||||
// store the old result value
|
||||
NewCode:='Result:='+NewCode;
|
||||
end;
|
||||
end;
|
||||
end else
|
||||
NewLine:=true; // procedures always on a separate line
|
||||
FromPos:=CleanPos;
|
||||
ToPos:=CleanPos;
|
||||
|
||||
if NewLine then begin
|
||||
// auto indent
|
||||
@ -269,15 +275,20 @@ begin
|
||||
and NewIndent.IndentValid then begin
|
||||
Indent:=NewIndent.Indent;
|
||||
end;
|
||||
while (FromPos>1) and (Tool.Src[FromPos-1] in [' ',#9]) do
|
||||
dec(FromPos);
|
||||
NewCode:=GetIndentStr(Indent)+NewCode;
|
||||
CleanPos:=GetLineStartPosition(Tool.Src,CleanPos);
|
||||
//debugln(['InsertCallInherited Indent=',Indent]);
|
||||
//debugln(['InsertCallInherited Indent=',Indent,' Line="',GetLineInSrc(Tool.Src,CleanPos),'"']);
|
||||
end;
|
||||
|
||||
NewCode:=CodeToolBoss.SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
||||
NewCode,Indent,[bcfDoNotIndentFirstLine],GetPosInLine(Tool.Src,CleanPos));
|
||||
NewCode,Indent,[bcfDoNotIndentFirstLine],GetPosInLine(Tool.Src,FromPos));
|
||||
CodeToolBoss.SourceChangeCache.MainScanner:=Tool.Scanner;
|
||||
if not CodeToolBoss.SourceChangeCache.Replace(Gap,Gap,CleanPos,CleanPos,NewCode)
|
||||
// move editor cursor in front of insert position
|
||||
NewXY:=Point(GetPosInLine(Tool.Src,FromPos)+1,SrcEdit.CursorTextXY.Y);
|
||||
//debugln(['InsertCallInherited NewXY=',dbgs(NewXY),' FromPos=',Tool.CleanPosToStr(FromPos),' ToPos=',Tool.CleanPosToStr(ToPos)]);
|
||||
SrcEdit.CursorTextXY:=NewXY;
|
||||
if not CodeToolBoss.SourceChangeCache.Replace(Gap,Gap,FromPos,ToPos,NewCode)
|
||||
then begin
|
||||
debugln(['InsertCallInherited CodeToolBoss.SourceChangeCache.Replace failed']);
|
||||
exit;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user