SynEdit & Cocoa: improve the handling of Lookup Word when the cursor is not on the text

This commit is contained in:
rich2014 2024-08-27 21:44:10 +08:00
parent d0353d68d8
commit c2d8e5ef9b
2 changed files with 10 additions and 5 deletions

View File

@ -178,15 +178,19 @@ procedure LazSynImeCocoa.LWRowColForScreenPoint(
var
localPoint: TPoint;
logicalPoint: TPoint;
pLine: pchar;
lineText: String;
begin
localPoint:= FriendEdit.ScreenToClient( screenPoint );
logicalPoint:= TSynEdit(FriendEdit).PixelsToLogicalPos( localPoint );
params.row:= logicalPoint.Y;
if params.row > 0 then
params.row:= params.row - 1;
pLine:= pchar( FriendEdit.Lines[params.row] );
params.col:= UTF8Length( pLine, logicalPoint.x ) - 1;
lineText:= FriendEdit.Lines[params.row];
if logicalPoint.x <= lineText.length then begin
params.col:= UTF8Length( pchar(lineText), logicalPoint.x ) - 1;
end else begin
params.col:= -1;
end;
end;
procedure LazSynImeCocoa.LWLineForRow( var params: TCocoaLWParameters );

View File

@ -460,12 +460,13 @@ var
params: TCocoaLWParameters;
lclPoint: TPoint;
begin
Result:= 0;
Result:= NSNotFound;
if NOT Assigned(self.lwHandler) then
Exit;
lclPoint:= ScreenPointFromNSToLCL( aPoint );
self.lwHandler.LWRowColForScreenPoint( params, lclPoint );
Result:= LWParamsToRange(params).location;
if params.col >= 0 then
Result:= LWParamsToRange(params).location;
end;
function TCocoaFullControlEdit.validAttributesForMarkedText: NSArray;