mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 03:35:57 +02:00
IDE: open file at cursor: adjust cursor if cursor is behind word
git-svn-id: trunk@56731 -
This commit is contained in:
parent
01020fb1c1
commit
14a1a07640
@ -1550,19 +1550,31 @@ var
|
|||||||
BaseDir: String;
|
BaseDir: String;
|
||||||
NewFilename,InFilename: string;
|
NewFilename,InFilename: string;
|
||||||
AUnitName: String;
|
AUnitName: String;
|
||||||
SearchPath: String;
|
SearchPath, Line: String;
|
||||||
Edit: TIDESynEditor;
|
Edit: TIDESynEditor;
|
||||||
FoundType: TFindFileAtCursorFlag;
|
FoundType: TFindFileAtCursorFlag;
|
||||||
|
XY: TPoint;
|
||||||
|
Len: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
|
|
||||||
|
{$IFDEF VerboseFindFileAtCursor}
|
||||||
|
debugln(['TFileOpener.OpenFileAtCursor ',FActiveUnitInfo<>nil]);
|
||||||
|
{$ENDIF}
|
||||||
if (FActiveSrcEdit=nil) or (FActiveUnitInfo=nil) then exit;
|
if (FActiveSrcEdit=nil) or (FActiveUnitInfo=nil) then exit;
|
||||||
BaseDir:=ExtractFilePath(FActiveUnitInfo.Filename);
|
BaseDir:=ExtractFilePath(FActiveUnitInfo.Filename);
|
||||||
|
{$IFDEF VerboseFindFileAtCursor}
|
||||||
|
debugln(['TFileOpener.OpenFileAtCursor File="',FActiveUnitInfo.Filename,'"']);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
Found:=false;
|
Found:=false;
|
||||||
|
|
||||||
// check if a filename is selected
|
// check if a filename is selected
|
||||||
Edit:=FActiveSrcEdit.EditorComponent;
|
Edit:=FActiveSrcEdit.EditorComponent;
|
||||||
if Edit.SelAvail and (Edit.BlockBegin.Y=Edit.BlockBegin.X) then begin
|
if Edit.SelAvail and (Edit.BlockBegin.Y=Edit.BlockBegin.X) then begin
|
||||||
|
{$IFDEF VerboseFindFileAtCursor}
|
||||||
|
debugln(['TFileOpener.OpenFileAtCursor Edit.SelAvail Edit.SelText="',Edit.SelText,'"']);
|
||||||
|
{$ENDIF}
|
||||||
FFileName:=ResolveDots(Edit.SelText);
|
FFileName:=ResolveDots(Edit.SelText);
|
||||||
if not FilenameIsAbsolute(FFileName) then
|
if not FilenameIsAbsolute(FFileName) then
|
||||||
FFileName:=ResolveDots(BaseDir+FFileName);
|
FFileName:=ResolveDots(BaseDir+FFileName);
|
||||||
@ -1574,10 +1586,26 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
XY:=Edit.LogicalCaretXY;
|
||||||
|
if (XY.Y >= 1) and (XY.Y <= FActiveSrcEdit.EditorComponent.Lines.Count) then
|
||||||
|
begin
|
||||||
|
Line := FActiveSrcEdit.EditorComponent.Lines.Strings[XY.Y - 1];
|
||||||
|
Len := Length(Line);
|
||||||
|
if (XY.X>1) and (XY.X-1<=Len) and IsWordChar[Line[XY.X-1]]
|
||||||
|
and ((XY.X>Len) or IsNonWordChar[Line[XY.X]]) then
|
||||||
|
dec(XY.X);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
// in a Pascal file use codetools
|
// in a Pascal file use codetools
|
||||||
if FilenameIsPascalSource(FActiveUnitInfo.Filename) then begin
|
if FilenameIsPascalSource(FActiveUnitInfo.Filename) then begin
|
||||||
|
{$IFDEF VerboseFindFileAtCursor}
|
||||||
|
debugln(['TFileOpener.OpenFileAtCursor FilenameIsPascalSource -> using codetools']);
|
||||||
|
{$ENDIF}
|
||||||
|
if MainIDE.BeginCodeTool(FActiveSrcEdit,FActiveUnitInfo,[]) then begin
|
||||||
if CodeToolBoss.FindFileAtCursor(FActiveSrcEdit.CodeBuffer,
|
if CodeToolBoss.FindFileAtCursor(FActiveSrcEdit.CodeBuffer,
|
||||||
Edit.LogicalCaretXY.X,Edit.LogicalCaretXY.Y,FoundType,FFileName) then
|
XY.X,XY.Y,FoundType,FFileName) then
|
||||||
Found:=true
|
Found:=true
|
||||||
else begin
|
else begin
|
||||||
FFileName:=FActiveSrcEdit.EditorComponent.GetWordAtRowCol(
|
FFileName:=FActiveSrcEdit.EditorComponent.GetWordAtRowCol(
|
||||||
@ -1585,6 +1613,7 @@ begin
|
|||||||
exit(ShowNotFound(FFileName));
|
exit(ShowNotFound(FFileName));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
if not Found then begin
|
if not Found then begin
|
||||||
// parse FFileName at cursor
|
// parse FFileName at cursor
|
||||||
|
Loading…
Reference in New Issue
Block a user