From 42721b9bee1fbb68dcf945b82dbb95a1d0b324f6 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 24 Jan 2012 19:04:33 +0000 Subject: [PATCH] IDE: find start of code block: when on start, jump to start of parent block git-svn-id: trunk@34906 - --- components/codetools/codetoolmanager.pas | 9 ++++--- components/codetools/stdcodetools.pas | 32 ++++++++++++++++++------ ide/main.pp | 2 +- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 08be02f201..715506a4a2 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -386,7 +386,8 @@ type out NewX, NewY, NewTopLine: integer): boolean; function FindBlockStart(Code: TCodeBuffer; X,Y: integer; out NewCode: TCodeBuffer; - out NewX, NewY, NewTopLine: integer): boolean; + out NewX, NewY, NewTopLine: integer; + SkipStart: boolean = false): boolean; function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean; @@ -3377,8 +3378,8 @@ begin {$ENDIF} end; -function TCodeToolManager.FindBlockStart(Code: TCodeBuffer; - X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer +function TCodeToolManager.FindBlockStart(Code: TCodeBuffer; X, Y: integer; out + NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer; SkipStart: boolean ): boolean; var CursorPos: TCodeXYPosition; @@ -3396,7 +3397,7 @@ begin DebugLn('TCodeToolManager.FindBlockStart B ',dbgs(FCurCodeTool.Scanner<>nil)); {$ENDIF} try - Result:=FCurCodeTool.FindBlockStart(CursorPos,NewPos,NewTopLine); + Result:=FCurCodeTool.FindBlockStart(CursorPos,NewPos,NewTopLine,SkipStart); if Result then begin NewX:=NewPos.X; NewY:=NewPos.Y; diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index b5f122796e..c79d350bf7 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -223,7 +223,8 @@ type function FindBlockCounterPart(const CursorPos: TCodeXYPosition; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; function FindBlockStart(const CursorPos: TCodeXYPosition; - out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; + out NewPos: TCodeXYPosition; out NewTopLine: integer; + SkipStart: boolean = true): boolean; function GuessUnclosedBlock(const CursorPos: TCodeXYPosition; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; function FindBlockCleanBounds(const CursorPos: TCodeXYPosition; @@ -4920,13 +4921,15 @@ begin Result:=CleanPosToCaretAndTopLine(CurPos.StartPos,NewPos,NewTopLine); end; -function TStandardCodeTool.FindBlockStart(const CursorPos: TCodeXYPosition; - out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; +function TStandardCodeTool.FindBlockStart(const CursorPos: TCodeXYPosition; out + NewPos: TCodeXYPosition; out NewTopLine: integer; SkipStart: boolean + ): boolean; // jump to beginning of current block // e.g. bracket open, 'begin', 'repeat', ... var CleanCursorPos: integer; CursorOnStart: Boolean; Node: TCodeTreeNode; + MinPos: Integer; begin Result:=false; // scan code @@ -4946,11 +4949,13 @@ begin end; end; Node:=FindDeepestNodeAtPos(CleanCursorPos,false); - //debugln(['TStandardCodeTool.FindBlockStart ',Node.DescAsString]); + //if Node<>nil then debugln(['TStandardCodeTool.FindBlockStart ',Node.DescAsString]); if (Node=nil) - or (Node.Desc in (AllPascalStatements+AllPascalTypes)) + or (Node.Desc in (AllPascalStatements+AllPascalTypes-AllClasses)) or (Src[CurPos.StartPos] in [')',']','}']) then begin + MinPos:=1; + if Node<>nil then MinPos:=Node.StartPos; repeat //debugln(['TStandardCodeTool.FindBlockStart atom ',CleanPosToStr(CurPos.StartPos),' ',GetAtom]); if (CurPos.StartPos<0) then begin @@ -4968,7 +4973,8 @@ begin CurPos.StartPos,CurPos.EndPos-CurPos.StartPos) then begin // block start found - exit(true); + if (CurPos.StartPosnil then begin + until CurPos.StartPosnil then begin + if SkipStart and (CleanCursorPos=Node.StartPos) then begin + while (Node<>nil) and (Node.StartPos=CleanCursorPos) do + Node:=Node.Parent; + if Node<>nil then + CurPos.StartPos:=Node.StartPos + else + CurPos.StartPos:=1; + exit(true); + end; if CleanCursorPos>=Node.StartPos then begin CurPos.StartPos:=Node.StartPos; exit(true); diff --git a/ide/main.pp b/ide/main.pp index 3937903d43..e51cd96344 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -15695,7 +15695,7 @@ begin if CodeToolBoss.FindBlockStart(ActiveUnitInfo.Source, ActiveSrcEdit.EditorComponent.CaretX, ActiveSrcEdit.EditorComponent.CaretY, - NewSource,NewX,NewY,NewTopLine) then + NewSource,NewX,NewY,NewTopLine,true) then begin Flags:=[jfFocusEditor]; if (ActiveSrcEdit.EditorComponent.CaretY<>NewY)