From 1f15c0c1c751d35eb8eec29a07c490e355671660 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 20 May 2004 14:14:39 +0000 Subject: [PATCH] implemented centered method jump to body with big headers git-svn-id: trunk@5487 - --- components/codetools/methodjumptool.pas | 53 +++++++++++++++++++------ ideintf/componenttreeview.pas | 1 - 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/components/codetools/methodjumptool.pas b/components/codetools/methodjumptool.pas index 4457a7e918..6887a0cf87 100644 --- a/components/codetools/methodjumptool.pas +++ b/components/codetools/methodjumptool.pas @@ -69,7 +69,8 @@ type function JumpToNode(ANode: TCodeTreeNode; var NewPos: TCodeXYPosition; var NewTopLine: integer; IgnoreJumpCentered: boolean): boolean; - function JumpToCleanPos(NewCleanPos, NewTopLineCleanPos: integer; + function JumpToCleanPos(NewCleanPos, NewTopLineCleanPos, + NewBottomLineCleanPos: integer; var NewPos: TCodeXYPosition; var NewTopLine: integer; IgnoreJumpCentered: boolean): boolean; function JumpToMethod(const ProcHead: string; Attr: TProcHeadAttributes; @@ -245,7 +246,8 @@ const {$IFDEF CTDEBUG} writeln('TMethodJumpingCodeTool.FindJumpPoint.JumpToProc D CleanDiffPos=',DiffPos); {$ENDIF} - Result:=JumpToCleanPos(DiffPos,ToProcNode.StartPos,NewPos,NewTopLine,true); + Result:=JumpToCleanPos(DiffPos,ToProcNode.StartPos,ToProcNode.EndPos, + NewPos,NewTopLine,true); end else begin // procs are equal if (ToProcNode.LastChild.Desc=ctnBeginBlock) then begin @@ -260,7 +262,8 @@ const writeln('TMethodJumpingCodeTool.FindJumpPoint.JumpToProc F proc has no body'); {$ENDIF} Result:=JumpToCleanPos(ToProcNode.FirstChild.StartPos, - ToProcNode.StartPos,NewPos,NewTopLine,false); + ToProcNode.StartPos,ToProcNode.EndPos,NewPos, + NewTopLine,false); end; RevertableJump:=true; end; @@ -689,8 +692,8 @@ begin DestNode:=FindProcBody(ProcNode); if DestNode=nil then begin // proc without body -> jump to proc node header - Result:=JumpToCleanPos(ProcNode.FirstChild.StartPos,ProcNode.Startpos, - NewPos,NewTopLine,false); + Result:=JumpToCleanPos(ProcNode.FirstChild.StartPos,ProcNode.StartPos, + ProcNode.EndPos,NewPos,NewTopLine,false); exit; end; // search good position @@ -744,7 +747,9 @@ begin end else i:=0; if NewCleanPos>SrcLen then NewCleanPos:=SrcLen; - if not JumpToCleanPos(NewCleanPos,ProcNode.StartPos,NewPos,NewTopLine,true) + + if not JumpToCleanPos(NewCleanPos,ProcNode.StartPos,ProcNode.EndPos, + NewPos,NewTopLine,true) then exit; if CursorBeyondEOL then inc(NewPos.x,i); @@ -885,7 +890,7 @@ function TMethodJumpingCodeTool.JumpToNode(ANode: TCodeTreeNode; begin Result:=false; if (ANode=nil) or (ANode.StartPos<1) then exit; - Result:=JumpToCleanPos(ANode.StartPos,ANode.StartPos, + Result:=JumpToCleanPos(ANode.StartPos,ANode.StartPos,ANode.EndPos, NewPos,NewTopLine,IgnoreJumpCentered); end; @@ -983,10 +988,13 @@ begin end; function TMethodJumpingCodeTool.JumpToCleanPos(NewCleanPos, - NewTopLineCleanPos: integer; var NewPos: TCodeXYPosition; - var NewTopLine: integer; IgnoreJumpCentered: boolean): boolean; -var CenteredTopLine: integer; + NewTopLineCleanPos, NewBottomLineCleanPos: integer; + var NewPos: TCodeXYPosition; var NewTopLine: integer; + IgnoreJumpCentered: boolean): boolean; +var + CenteredTopLine: integer; NewTopLinePos: TCodeXYPosition; + NewBottomLinePos: TCodeXYPosition; begin Result:=false; // convert clean position to line, column and code @@ -1008,18 +1016,37 @@ begin end; // convert clean top line position to line, column and code if not CleanPosToCaret(NewTopLineCleanPos,NewTopLinePos) then exit; + // convert clea bottom line position to line, column and code + NewBottomLinePos:=NewPos; + if (NewBottomLineCleanPos>NewCleanPos) + and (not CleanPosToCaret(NewBottomLineCleanPos,NewBottomLinePos)) then exit; + if NewTopLinePos.Code=NewPos.Code then begin // top line position is in the same code as the destination position NewTopLine:=NewTopLinePos.Y; + CenteredTopLine:=NewPos.Y-VisibleEditorLines div 2; if JumpCentered and (not IgnoreJumpCentered) then begin // center the destination position in the source editor - CenteredTopLine:=NewPos.Y-VisibleEditorLines div 2; if CenteredTopLineNewCleanPos) + and (NewBottomLinePos.Y