mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-25 09:19:31 +01:00
IDE: find start of code block: when on start, jump to start of parent block
git-svn-id: trunk@34906 -
This commit is contained in:
parent
a7a3a71ce2
commit
42721b9bee
@ -386,7 +386,8 @@ type
|
|||||||
out NewX, NewY, NewTopLine: integer): boolean;
|
out NewX, NewY, NewTopLine: integer): boolean;
|
||||||
function FindBlockStart(Code: TCodeBuffer; X,Y: integer;
|
function FindBlockStart(Code: TCodeBuffer; X,Y: integer;
|
||||||
out NewCode: TCodeBuffer;
|
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;
|
function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer;
|
||||||
out NewCode: TCodeBuffer;
|
out NewCode: TCodeBuffer;
|
||||||
out NewX, NewY, NewTopLine: integer): boolean;
|
out NewX, NewY, NewTopLine: integer): boolean;
|
||||||
@ -3377,8 +3378,8 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.FindBlockStart(Code: TCodeBuffer;
|
function TCodeToolManager.FindBlockStart(Code: TCodeBuffer; X, Y: integer; out
|
||||||
X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer
|
NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer; SkipStart: boolean
|
||||||
): boolean;
|
): boolean;
|
||||||
var
|
var
|
||||||
CursorPos: TCodeXYPosition;
|
CursorPos: TCodeXYPosition;
|
||||||
@ -3396,7 +3397,7 @@ begin
|
|||||||
DebugLn('TCodeToolManager.FindBlockStart B ',dbgs(FCurCodeTool.Scanner<>nil));
|
DebugLn('TCodeToolManager.FindBlockStart B ',dbgs(FCurCodeTool.Scanner<>nil));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
try
|
try
|
||||||
Result:=FCurCodeTool.FindBlockStart(CursorPos,NewPos,NewTopLine);
|
Result:=FCurCodeTool.FindBlockStart(CursorPos,NewPos,NewTopLine,SkipStart);
|
||||||
if Result then begin
|
if Result then begin
|
||||||
NewX:=NewPos.X;
|
NewX:=NewPos.X;
|
||||||
NewY:=NewPos.Y;
|
NewY:=NewPos.Y;
|
||||||
|
|||||||
@ -223,7 +223,8 @@ type
|
|||||||
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
|
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
function FindBlockStart(const CursorPos: TCodeXYPosition;
|
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;
|
function GuessUnclosedBlock(const CursorPos: TCodeXYPosition;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
function FindBlockCleanBounds(const CursorPos: TCodeXYPosition;
|
function FindBlockCleanBounds(const CursorPos: TCodeXYPosition;
|
||||||
@ -4920,13 +4921,15 @@ begin
|
|||||||
Result:=CleanPosToCaretAndTopLine(CurPos.StartPos,NewPos,NewTopLine);
|
Result:=CleanPosToCaretAndTopLine(CurPos.StartPos,NewPos,NewTopLine);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.FindBlockStart(const CursorPos: TCodeXYPosition;
|
function TStandardCodeTool.FindBlockStart(const CursorPos: TCodeXYPosition; out
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
NewPos: TCodeXYPosition; out NewTopLine: integer; SkipStart: boolean
|
||||||
|
): boolean;
|
||||||
// jump to beginning of current block
|
// jump to beginning of current block
|
||||||
// e.g. bracket open, 'begin', 'repeat', ...
|
// e.g. bracket open, 'begin', 'repeat', ...
|
||||||
var CleanCursorPos: integer;
|
var CleanCursorPos: integer;
|
||||||
CursorOnStart: Boolean;
|
CursorOnStart: Boolean;
|
||||||
Node: TCodeTreeNode;
|
Node: TCodeTreeNode;
|
||||||
|
MinPos: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
// scan code
|
// scan code
|
||||||
@ -4946,11 +4949,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Node:=FindDeepestNodeAtPos(CleanCursorPos,false);
|
Node:=FindDeepestNodeAtPos(CleanCursorPos,false);
|
||||||
//debugln(['TStandardCodeTool.FindBlockStart ',Node.DescAsString]);
|
//if Node<>nil then debugln(['TStandardCodeTool.FindBlockStart ',Node.DescAsString]);
|
||||||
if (Node=nil)
|
if (Node=nil)
|
||||||
or (Node.Desc in (AllPascalStatements+AllPascalTypes))
|
or (Node.Desc in (AllPascalStatements+AllPascalTypes-AllClasses))
|
||||||
or (Src[CurPos.StartPos] in [')',']','}'])
|
or (Src[CurPos.StartPos] in [')',']','}'])
|
||||||
then begin
|
then begin
|
||||||
|
MinPos:=1;
|
||||||
|
if Node<>nil then MinPos:=Node.StartPos;
|
||||||
repeat
|
repeat
|
||||||
//debugln(['TStandardCodeTool.FindBlockStart atom ',CleanPosToStr(CurPos.StartPos),' ',GetAtom]);
|
//debugln(['TStandardCodeTool.FindBlockStart atom ',CleanPosToStr(CurPos.StartPos),' ',GetAtom]);
|
||||||
if (CurPos.StartPos<0) then begin
|
if (CurPos.StartPos<0) then begin
|
||||||
@ -4968,6 +4973,7 @@ begin
|
|||||||
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos) then
|
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos) then
|
||||||
begin
|
begin
|
||||||
// block start found
|
// block start found
|
||||||
|
if (CurPos.StartPos<CleanCursorPos) or (not SkipStart) then
|
||||||
exit(true);
|
exit(true);
|
||||||
end else if UpAtomIs('END') or UpAtomIs('FINALLY') or UpAtomIs('EXCEPT')
|
end else if UpAtomIs('END') or UpAtomIs('FINALLY') or UpAtomIs('EXCEPT')
|
||||||
or UpAtomIs('UNTIL') then
|
or UpAtomIs('UNTIL') then
|
||||||
@ -4979,8 +4985,18 @@ begin
|
|||||||
if CursorOnStart then exit(true);
|
if CursorOnStart then exit(true);
|
||||||
end;
|
end;
|
||||||
ReadPriorAtom;
|
ReadPriorAtom;
|
||||||
until false;
|
until CurPos.StartPos<MinPos;
|
||||||
end else if Node<>nil then begin
|
end;
|
||||||
|
if Node<>nil 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
|
if CleanCursorPos>=Node.StartPos then begin
|
||||||
CurPos.StartPos:=Node.StartPos;
|
CurPos.StartPos:=Node.StartPos;
|
||||||
exit(true);
|
exit(true);
|
||||||
|
|||||||
@ -15695,7 +15695,7 @@ begin
|
|||||||
if CodeToolBoss.FindBlockStart(ActiveUnitInfo.Source,
|
if CodeToolBoss.FindBlockStart(ActiveUnitInfo.Source,
|
||||||
ActiveSrcEdit.EditorComponent.CaretX,
|
ActiveSrcEdit.EditorComponent.CaretX,
|
||||||
ActiveSrcEdit.EditorComponent.CaretY,
|
ActiveSrcEdit.EditorComponent.CaretY,
|
||||||
NewSource,NewX,NewY,NewTopLine) then
|
NewSource,NewX,NewY,NewTopLine,true) then
|
||||||
begin
|
begin
|
||||||
Flags:=[jfFocusEditor];
|
Flags:=[jfFocusEditor];
|
||||||
if (ActiveSrcEdit.EditorComponent.CaretY<>NewY)
|
if (ActiveSrcEdit.EditorComponent.CaretY<>NewY)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user