mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 03:59:13 +02:00
IDE, SourceEditer: Fix/Improve detection if text-cursor is at ident for "find identifier reference". Issue #41020
This commit is contained in:
parent
bb2caca569
commit
f8c74b8794
@ -1009,7 +1009,8 @@ type
|
|||||||
out Attri: TSynHighlighterAttributes): boolean;
|
out Attri: TSynHighlighterAttributes): boolean;
|
||||||
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
|
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
|
||||||
out TokenType, Start: Integer;
|
out TokenType, Start: Integer;
|
||||||
out Attri: TSynHighlighterAttributes): boolean;
|
out Attri: TSynHighlighterAttributes;
|
||||||
|
ContinueIfPossible: boolean = False): boolean;
|
||||||
function GetHighlighterAttriAtRowColEx(XY: TPoint; out TokenType: Integer; ContinueIfPossible: boolean = False): boolean;
|
function GetHighlighterAttriAtRowColEx(XY: TPoint; out TokenType: Integer; ContinueIfPossible: boolean = False): boolean;
|
||||||
procedure CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
|
procedure CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
|
||||||
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer); override;
|
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer); override;
|
||||||
@ -9684,9 +9685,9 @@ begin
|
|||||||
Result := GetHighlighterAttriAtRowColEx(XY, Token, TmpType, TmpStart, Attri);
|
Result := GetHighlighterAttriAtRowColEx(XY, Token, TmpType, TmpStart, Attri);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynEdit.GetHighlighterAttriAtRowColEx(XY: TPoint;
|
function TCustomSynEdit.GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string; out
|
||||||
out Token: string; out TokenType, Start: Integer;
|
TokenType, Start: Integer; out Attri: TSynHighlighterAttributes; ContinueIfPossible: boolean
|
||||||
out Attri: TSynHighlighterAttributes): boolean;
|
): boolean;
|
||||||
var
|
var
|
||||||
PosX, PosY: integer;
|
PosX, PosY: integer;
|
||||||
Line: string;
|
Line: string;
|
||||||
@ -9697,8 +9698,14 @@ begin
|
|||||||
Line := FTheLinesView[PosY];
|
Line := FTheLinesView[PosY];
|
||||||
PosX := XY.X;
|
PosX := XY.X;
|
||||||
if (PosX > 0) and (PosX <= Length(Line)) then begin
|
if (PosX > 0) and (PosX <= Length(Line)) then begin
|
||||||
|
if (not ContinueIfPossible) or
|
||||||
|
(fHighlighter.CurrentLines <> FTheLinesView) or
|
||||||
|
(fHighlighter.LineIndex <> PosY) or
|
||||||
|
(fHighlighter.GetTokenPos + 1 + Highlighter.GetTokenLen >= PosX)
|
||||||
|
then begin
|
||||||
fHighlighter.CurrentLines := FTheLinesView;
|
fHighlighter.CurrentLines := FTheLinesView;
|
||||||
Highlighter.StartAtLineIndex(PosY);
|
Highlighter.StartAtLineIndex(PosY);
|
||||||
|
end;
|
||||||
while not Highlighter.GetEol do begin
|
while not Highlighter.GetEol do begin
|
||||||
Start := Highlighter.GetTokenPos + 1;
|
Start := Highlighter.GetTokenPos + 1;
|
||||||
Token := Highlighter.GetToken;
|
Token := Highlighter.GetToken;
|
||||||
|
47
ide/main.pp
47
ide/main.pp
@ -76,7 +76,7 @@ uses
|
|||||||
{$IFDEF LCLWin} Win32Proc, {$ENDIF}
|
{$IFDEF LCLWin} Win32Proc, {$ENDIF}
|
||||||
{$IFDEF LCLCocoa} CocoaMenus, {$ENDIF}
|
{$IFDEF LCLCocoa} CocoaMenus, {$ENDIF}
|
||||||
// SynEdit
|
// SynEdit
|
||||||
SynEdit, AllSynEdit, SynEditKeyCmds, SynEditMarks, SynEditHighlighter,
|
SynEdit, AllSynEdit, SynEditKeyCmds, SynEditMarks, SynEditHighlighter, SynHighlighterPas,
|
||||||
// BuildIntf
|
// BuildIntf
|
||||||
BaseIDEIntf, MacroIntf, NewItemIntf, IDEExternToolIntf, LazMsgWorker,
|
BaseIDEIntf, MacroIntf, NewItemIntf, IDEExternToolIntf, LazMsgWorker,
|
||||||
PackageIntf, ProjectIntf, CompOptsIntf, IDEOptionsIntf, ComponentReg,
|
PackageIntf, ProjectIntf, CompOptsIntf, IDEOptionsIntf, ComponentReg,
|
||||||
@ -3987,10 +3987,13 @@ var
|
|||||||
Editable, SelEditable: Boolean;
|
Editable, SelEditable: Boolean;
|
||||||
SelAvail, DesignerCanCopy: Boolean;
|
SelAvail, DesignerCanCopy: Boolean;
|
||||||
SrcEditorActive, DsgEditorActive: Boolean;
|
SrcEditorActive, DsgEditorActive: Boolean;
|
||||||
IdentFound, StringFound: Boolean;
|
IdentFound, StringFound, cont: Boolean;
|
||||||
ActiveDesigner: TComponentEditorDesigner;
|
ActiveDesigner: TComponentEditorDesigner;
|
||||||
CurWordAtCursor: string;
|
CurWordAtCursor, TokenTxt: string;
|
||||||
FindDeclarationCmd: TIDECommand;
|
FindDeclarationCmd: TIDECommand;
|
||||||
|
i, TokenType, Start: Integer;
|
||||||
|
Attri: TSynHighlighterAttributes;
|
||||||
|
xy: TPoint;
|
||||||
begin
|
begin
|
||||||
GetCurrentUnit(ASrcEdit, AnUnitInfo);
|
GetCurrentUnit(ASrcEdit, AnUnitInfo);
|
||||||
ActiveDesigner := GetActiveDesignerSkipMainBar;
|
ActiveDesigner := GetActiveDesignerSkipMainBar;
|
||||||
@ -4004,17 +4007,45 @@ begin
|
|||||||
SrcEditorActive := DisplayState = dsSource;
|
SrcEditorActive := DisplayState = dsSource;
|
||||||
DsgEditorActive := DisplayState = dsForm;
|
DsgEditorActive := DisplayState = dsForm;
|
||||||
|
|
||||||
|
IdentFound := False;
|
||||||
|
StringFound := False;
|
||||||
if ASrcEdit<>nil then
|
if ASrcEdit<>nil then
|
||||||
begin
|
begin
|
||||||
CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
|
CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
|
||||||
//it is faster to get information from SynEdit than from CodeTools
|
|
||||||
ASrcEdit.EditorComponent.CaretAtIdentOrString(ASrcEdit.EditorComponent.CaretXY,
|
if ASrcEdit.EditorComponent.Highlighter is TSynPasSyn then begin
|
||||||
IdentFound, StringFound);
|
xy := ASrcEdit.EditorComponent.CaretXY;
|
||||||
|
cont := False;
|
||||||
|
if xy.X > 1 then begin
|
||||||
|
dec(xy.x); // look at the very end of the token
|
||||||
|
ASrcEdit.EditorComponent.GetHighlighterAttriAtRowColEx(xy,
|
||||||
|
TokenTxt, TokenType, Start, Attri);
|
||||||
|
inc(xy.x);
|
||||||
|
if Start + Length(TokenTxt) = xy.X then begin
|
||||||
|
IdentFound := TtkTokenKind(TokenType) in [tkAsm, tkComment, tkIdentifier, tkString];
|
||||||
|
StringFound := TtkTokenKind(TokenType) = tkString;
|
||||||
|
end;
|
||||||
|
cont := True;
|
||||||
|
end;
|
||||||
|
if not (IdentFound or StringFound) then begin
|
||||||
|
ASrcEdit.EditorComponent.GetHighlighterAttriAtRowColEx(xy,
|
||||||
|
TokenTxt, TokenType, Start, Attri, cont);
|
||||||
|
IdentFound := TtkTokenKind(TokenType) in [tkAsm, tkComment, tkIdentifier, tkString];
|
||||||
|
StringFound := TtkTokenKind(TokenType) = tkString;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if IdentFound then begin
|
||||||
|
IdentFound := (CurWordAtCursor <> '') and (CurWordAtCursor[1] in ['A'..'Z', 'a'..'z', '_']);
|
||||||
|
i := 2;
|
||||||
|
while IdentFound and (i <= Length(CurWordAtCursor)) do begin
|
||||||
|
IdentFound := CurWordAtCursor[i] in ['A'..'Z', 'a'..'z', '_', '0'..'9'];
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
CurWordAtCursor := '';
|
CurWordAtCursor := '';
|
||||||
IdentFound := False;
|
|
||||||
StringFound := False;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Assigned(ActiveDesigner) then
|
if Assigned(ActiveDesigner) then
|
||||||
|
Loading…
Reference in New Issue
Block a user