getSelectionScreenRect method
Get selection bounds in screen coordinates.
windowBounds - The palette window's bounds from PaletteSelf.screenRect.
Implementation
ScreenRect? getSelectionScreenRect(
TextEditingController controller,
ScreenRect windowBounds,
) {
final viewRect = getSelectionRectInView(controller);
if (viewRect == null) return null;
// Convert view coordinates to screen coordinates
final screenTopLeft = windowBounds.localToScreen(
Offset(viewRect.left, viewRect.top),
);
final screenBottomRight = windowBounds.localToScreen(
Offset(viewRect.right, viewRect.bottom),
);
// On macOS, Y is flipped, so we need to handle it correctly
if (windowBounds.isMacOS) {
return ScreenRect(
Rect.fromLTRB(
screenTopLeft.dx,
screenBottomRight.dy, // bottom becomes top in macOS coords
screenBottomRight.dx,
screenTopLeft.dy, // top becomes bottom in macOS coords
),
isMacOS: true,
);
}
return ScreenRect(
Rect.fromLTRB(
screenTopLeft.dx,
screenTopLeft.dy,
screenBottomRight.dx,
screenBottomRight.dy,
),
isMacOS: false,
);
}