diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index b6affd45a9..0a62279e3c 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -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 - fHighlighter.CurrentLines := FTheLinesView; - Highlighter.StartAtLineIndex(PosY); + 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; diff --git a/ide/main.pp b/ide/main.pp index 40340a86e4..205da4ee69 100644 --- a/ide/main.pp +++ b/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