mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-27 02:28:57 +01:00
IDE: Enable "Make Resource String" command also when cursor is behind an end-quote. Issue #28829.
git-svn-id: trunk@51084 -
This commit is contained in:
parent
e0c99b1197
commit
0a7cc81dde
@ -974,6 +974,7 @@ type
|
||||
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
|
||||
out TokenType, Start: Integer;
|
||||
out Attri: TSynHighlighterAttributes): boolean; //L505
|
||||
procedure CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
|
||||
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer);
|
||||
function GetWordAtRowCol(XY: TPoint): string;
|
||||
function NextTokenPos: TPoint; virtual; deprecated; // use next word pos instead
|
||||
@ -8830,8 +8831,7 @@ begin
|
||||
if (PosX >= Start) and (PosX < Start + Length(Token)) then begin
|
||||
Attri := Highlighter.GetTokenAttribute;
|
||||
TokenType := Highlighter.GetTokenKind;
|
||||
Result := TRUE;
|
||||
exit;
|
||||
exit(True);
|
||||
end;
|
||||
Highlighter.Next;
|
||||
end;
|
||||
@ -8840,7 +8840,53 @@ begin
|
||||
Token := '';
|
||||
Attri := nil;
|
||||
TokenType := -1;
|
||||
Result := FALSE;
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
|
||||
// This is optimized to check if cursor is on identifier or string.
|
||||
var
|
||||
PosX, PosY: integer;
|
||||
Line, Token: string;
|
||||
Start: Integer;
|
||||
Attri, PrevAttri: TSynHighlighterAttributes;
|
||||
begin
|
||||
PosY := XY.Y -1;
|
||||
PrevAttri := nil;
|
||||
AtIdent := False;
|
||||
NearString := False;
|
||||
//DebugLn('');
|
||||
//DebugLn('TCustomSynEdit.CaretAtIdentOrString: Enter');
|
||||
if Assigned(Highlighter) and (PosY >= 0) and (PosY < FTheLinesView.Count) then
|
||||
begin
|
||||
Line := FTheLinesView[PosY];
|
||||
fHighlighter.CurrentLines := FTheLinesView;
|
||||
Highlighter.StartAtLineIndex(PosY);
|
||||
PosX := XY.X;
|
||||
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Line="', Line, '", PosX=', PosX, ', PosY=', PosY]);
|
||||
if (PosX > 0) and (PosX <= Length(Line)) then
|
||||
begin
|
||||
while not Highlighter.GetEol do
|
||||
begin
|
||||
Start := Highlighter.GetTokenPos + 1;
|
||||
Token := Highlighter.GetToken;
|
||||
//TokenType := Highlighter.GetTokenKind;
|
||||
Attri := Highlighter.GetTokenAttribute;
|
||||
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Start=', Start, ', Token=', Token]);
|
||||
if (PosX >= Start) and (PosX < Start + Length(Token)) then
|
||||
begin
|
||||
AtIdent := Attri = Highlighter.IdentifierAttribute;
|
||||
NearString := (Attri = Highlighter.StringAttribute)
|
||||
or (PrevAttri = Highlighter.StringAttribute); // If cursor is on end-quote.
|
||||
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Success! Attri=', Attri,
|
||||
// ', AtIdent=', AtIdent, ', AtString=', AtString]);
|
||||
exit;
|
||||
end;
|
||||
PrevAttri := Attri;
|
||||
Highlighter.Next;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomSynEdit.IdentChars: TSynIdentChars;
|
||||
|
||||
19
ide/main.pp
19
ide/main.pp
@ -3643,10 +3643,9 @@ var
|
||||
Editable: Boolean;
|
||||
SelAvail: Boolean;
|
||||
SelEditable: Boolean;
|
||||
SrcEditorActive, DsgEditorActive, StringFound, IdentFound: Boolean;
|
||||
SrcEditorActive, DsgEditorActive, IdentFound, StringFound: Boolean;
|
||||
ActiveDesigner: TComponentEditorDesigner;
|
||||
xAttr: TSynHighlighterAttributes;
|
||||
xToken, CurWordAtCursor: string;
|
||||
CurWordAtCursor: string;
|
||||
begin
|
||||
GetCurrentUnit(ASrcEdit, AnUnitInfo);
|
||||
if not UpdateEditorCommandsStamp.Changed(ASrcEdit, DisplayState) then
|
||||
@ -3659,18 +3658,16 @@ begin
|
||||
DsgEditorActive := DisplayState = dsForm;
|
||||
ActiveDesigner := GetActiveDesignerSkipMainBar;
|
||||
|
||||
StringFound := False;
|
||||
IdentFound := False;
|
||||
CurWordAtCursor := '';
|
||||
if ASrcEdit<>nil then
|
||||
begin
|
||||
CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
|
||||
//it is faster to get information from SynEdit than from CodeTools
|
||||
if ASrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(ASrcEdit.EditorComponent.CaretXY, xToken, xAttr) then
|
||||
begin
|
||||
StringFound := xAttr = ASrcEdit.EditorComponent.Highlighter.StringAttribute;
|
||||
IdentFound := xAttr = ASrcEdit.EditorComponent.Highlighter.IdentifierAttribute;
|
||||
end;
|
||||
ASrcEdit.EditorComponent.CaretAtIdentOrString(ASrcEdit.EditorComponent.CaretXY, IdentFound, StringFound);
|
||||
end
|
||||
else begin
|
||||
CurWordAtCursor := '';
|
||||
IdentFound := False;
|
||||
StringFound := False;
|
||||
end;
|
||||
|
||||
if Assigned(ActiveDesigner) then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user