mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 10:59:19 +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;
|
||||
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
|
||||
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;
|
||||
procedure CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
|
||||
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer); override;
|
||||
@ -9684,9 +9685,9 @@ begin
|
||||
Result := GetHighlighterAttriAtRowColEx(XY, Token, TmpType, TmpStart, Attri);
|
||||
end;
|
||||
|
||||
function TCustomSynEdit.GetHighlighterAttriAtRowColEx(XY: TPoint;
|
||||
out Token: string; out TokenType, Start: Integer;
|
||||
out Attri: TSynHighlighterAttributes): boolean;
|
||||
function TCustomSynEdit.GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string; out
|
||||
TokenType, Start: Integer; out Attri: TSynHighlighterAttributes; ContinueIfPossible: boolean
|
||||
): boolean;
|
||||
var
|
||||
PosX, PosY: integer;
|
||||
Line: string;
|
||||
@ -9697,8 +9698,14 @@ begin
|
||||
Line := FTheLinesView[PosY];
|
||||
PosX := XY.X;
|
||||
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;
|
||||
Highlighter.StartAtLineIndex(PosY);
|
||||
end;
|
||||
while not Highlighter.GetEol do begin
|
||||
Start := Highlighter.GetTokenPos + 1;
|
||||
Token := Highlighter.GetToken;
|
||||
|
47
ide/main.pp
47
ide/main.pp
@ -76,7 +76,7 @@ uses
|
||||
{$IFDEF LCLWin} Win32Proc, {$ENDIF}
|
||||
{$IFDEF LCLCocoa} CocoaMenus, {$ENDIF}
|
||||
// SynEdit
|
||||
SynEdit, AllSynEdit, SynEditKeyCmds, SynEditMarks, SynEditHighlighter,
|
||||
SynEdit, AllSynEdit, SynEditKeyCmds, SynEditMarks, SynEditHighlighter, SynHighlighterPas,
|
||||
// BuildIntf
|
||||
BaseIDEIntf, MacroIntf, NewItemIntf, IDEExternToolIntf, LazMsgWorker,
|
||||
PackageIntf, ProjectIntf, CompOptsIntf, IDEOptionsIntf, ComponentReg,
|
||||
@ -3987,10 +3987,13 @@ var
|
||||
Editable, SelEditable: Boolean;
|
||||
SelAvail, DesignerCanCopy: Boolean;
|
||||
SrcEditorActive, DsgEditorActive: Boolean;
|
||||
IdentFound, StringFound: Boolean;
|
||||
IdentFound, StringFound, cont: Boolean;
|
||||
ActiveDesigner: TComponentEditorDesigner;
|
||||
CurWordAtCursor: string;
|
||||
CurWordAtCursor, TokenTxt: string;
|
||||
FindDeclarationCmd: TIDECommand;
|
||||
i, TokenType, Start: Integer;
|
||||
Attri: TSynHighlighterAttributes;
|
||||
xy: TPoint;
|
||||
begin
|
||||
GetCurrentUnit(ASrcEdit, AnUnitInfo);
|
||||
ActiveDesigner := GetActiveDesignerSkipMainBar;
|
||||
@ -4004,17 +4007,45 @@ begin
|
||||
SrcEditorActive := DisplayState = dsSource;
|
||||
DsgEditorActive := DisplayState = dsForm;
|
||||
|
||||
IdentFound := False;
|
||||
StringFound := False;
|
||||
if ASrcEdit<>nil then
|
||||
begin
|
||||
CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
|
||||
//it is faster to get information from SynEdit than from CodeTools
|
||||
ASrcEdit.EditorComponent.CaretAtIdentOrString(ASrcEdit.EditorComponent.CaretXY,
|
||||
IdentFound, StringFound);
|
||||
|
||||
if ASrcEdit.EditorComponent.Highlighter is TSynPasSyn then begin
|
||||
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
|
||||
else begin
|
||||
CurWordAtCursor := '';
|
||||
IdentFound := False;
|
||||
StringFound := False;
|
||||
end;
|
||||
|
||||
if Assigned(ActiveDesigner) then
|
||||
|
Loading…
Reference in New Issue
Block a user