Implement "Select code block"

git-svn-id: trunk@64672 -
This commit is contained in:
martin 2021-02-26 22:01:33 +00:00
parent b18c1a22df
commit 06eb834614
4 changed files with 68 additions and 16 deletions

View File

@ -447,7 +447,8 @@ type
// blocks (e.g. begin..end, case..end, try..finally..end, repeat..until)
function FindBlockCounterPart(Code: TCodeBuffer; X,Y: integer;
out NewCode: TCodeBuffer;
out NewX, NewY, NewTopLine: integer): boolean;
out NewX, NewY, NewTopLine: integer;
IncludeCloseToken: Boolean = false): boolean;
function FindBlockStart(Code: TCodeBuffer; X,Y: integer;
out NewCode: TCodeBuffer;
out NewX, NewY, NewTopLine: integer;
@ -3690,9 +3691,9 @@ begin
{$ENDIF}
end;
function TCodeToolManager.FindBlockCounterPart(Code: TCodeBuffer;
X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer
): boolean;
function TCodeToolManager.FindBlockCounterPart(Code: TCodeBuffer; X,
Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer;
IncludeCloseToken: Boolean): boolean;
var
CursorPos: TCodeXYPosition;
NewPos: TCodeXYPosition;
@ -3710,7 +3711,7 @@ begin
DebugLn('TCodeToolManager.FindBlockCounterPart B ',dbgs(FCurCodeTool.Scanner<>nil));
{$ENDIF}
try
Result:=FCurCodeTool.FindBlockCounterPart(CursorPos,NewPos,NewTopLine);
Result:=FCurCodeTool.FindBlockCounterPart(CursorPos,NewPos,NewTopLine,IncludeCloseToken);
if Result then begin
NewX:=NewPos.X;
NewY:=NewPos.Y;

View File

@ -260,7 +260,8 @@ type
// blocks (e.g. begin..end)
function FindBlockCounterPart(const CursorPos: TCodeXYPosition;
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
out NewPos: TCodeXYPosition; out NewTopLine: integer;
IncludeCloseToken: Boolean = false): boolean;
function FindBlockStart(const CursorPos: TCodeXYPosition;
out NewPos: TCodeXYPosition; out NewTopLine: integer;
SkipStart: boolean = true): boolean;
@ -5092,8 +5093,8 @@ begin
end;
function TStandardCodeTool.FindBlockCounterPart(
const CursorPos: TCodeXYPosition;
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
const CursorPos: TCodeXYPosition; out NewPos: TCodeXYPosition; out
NewTopLine: integer; IncludeCloseToken: Boolean): boolean;
// jump from bracket-open to bracket-close or 'begin' to 'end'
// or 'until' to 'repeat' ...
var CleanCursorPos: integer;
@ -5130,6 +5131,8 @@ begin
end else
exit;
end;
if IncludeCloseToken then
ReadNextAtom;
// CursorPos now contains the counter block keyword
Result:=CleanPosToCaretAndTopLine(CurPos.StartPos,NewPos,NewTopLine);
end;

View File

@ -914,6 +914,7 @@ type
function DoCheckSyntax: TModalResult;
procedure DoGoToPascalBlockOtherEnd;
procedure DoGoToPascalBlockStart;
procedure SelectCodeBlock;
procedure DoJumpToGuessedUnclosedBlock(FindNextUTF8: boolean);
{$IFDEF GuessMisplacedIfdef}
procedure DoJumpToGuessedMisplacedIFDEF(FindNextUTF8: boolean);
@ -3574,6 +3575,7 @@ begin
ecFindOverloads: DoFindOverloads;
ecFindBlockOtherEnd: DoGoToPascalBlockOtherEnd;
ecFindBlockStart: DoGoToPascalBlockStart;
ecSelectCodeBlock: SelectCodeBlock;
ecGotoIncludeDirective: DoGotoIncludeDirective;
ecCompleteCode: DoCompleteCodeAtCursor(False);
ecCompleteCodeInteractive: DoCompleteCodeAtCursor(True);
@ -10517,6 +10519,60 @@ begin
DoJumpToCodeToolBossError;
end;
procedure TMainIDE.SelectCodeBlock;
var
ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
NewSource: TCodeBuffer;
OldX, OldY,
NewX, NewY, NewX2, NewY2, NewTopLine, NewTopLine2: integer;
Flags: TJumpToCodePosFlags;
s: String;
begin
ActiveSrcEdit:=nil;
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then
exit;
if ActiveSrcEdit.SelectionAvailable and not ActiveSrcEdit.EditorComponent.IsBackwardSel then begin
OldY := ActiveSrcEdit.BlockBegin.y;
OldX := ActiveSrcEdit.BlockBegin.x;
end
else begin
OldY := ActiveSrcEdit.EditorComponent.CaretY;
OldX := ActiveSrcEdit.EditorComponent.LogicalCaretXY.X;
end;
if not CodeToolBoss.FindBlockStart(ActiveUnitInfo.Source,
OldX, OldY,
NewSource,NewX,NewY,NewTopLine,true) then
begin
DoJumpToCodeToolBossError;
exit;
end;
if not CodeToolBoss.FindBlockCounterPart(ActiveUnitInfo.Source,
NewX, NewY,
NewSource,NewX2,NewY2,NewTopLine2,
true) then
begin
DoJumpToCodeToolBossError;
exit;
end;
s := ActiveSrcEdit.EditorComponent.TextBetweenPoints[Point(1, NewY2), Point(NewX2+1, NewY2)];
NewX2 := Min(NewX2, Length(s)+1);
while (NewX2 > 1) and (s[NewX2-1] in [#9,#32]) do
dec(NewX2);
Flags:=[jfFocusEditor];
if (OldY<>NewY2) or (Abs(OldX-NewX2)>10) then
Include(Flags,jfAddJumpPoint);
DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
NewSource, NewX2, NewY2, NewTopLine, NewY, NewY2, Flags);
ActiveSrcEdit.SelectText(Point(NewX, NewY), Point(NewX2, NewY2));
end;
procedure TMainIDE.DoJumpToGuessedUnclosedBlock(FindNextUTF8: boolean);
var ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;

View File

@ -425,7 +425,6 @@ type
procedure BreakLinesInSelection;
procedure InvertAssignment;
procedure SelectToBrace;
procedure SelectCodeBlock;
procedure SelectWord;
procedure SelectLine;
procedure SelectParagraph;
@ -4147,7 +4146,6 @@ Begin
ecSelectionBreakLines: BreakLinesInSelection;
ecInvertAssignment: InvertAssignment;
ecSelectToBrace: SelectToBrace;
ecSelectCodeBlock: SelectCodeBlock;
ecSelectLine: SelectLine;
ecSelectWord: SelectWord;
ecSelectParagraph: SelectParagraph;
@ -4554,12 +4552,6 @@ begin
EditorComponent.SelectToBrace;
end;
procedure TSourceEditor.SelectCodeBlock;
begin
// ToDo:
DebugLn('TSourceEditor.SelectCodeBlock: not implemented yet');
end;
procedure TSourceEditor.SelectWord;
begin
EditorComponent.SelectWord;