From bb193061687ab372bd7bbf720ab80bcf13d2879f Mon Sep 17 00:00:00 2001 From: Aleksandr Neychev Date: Sun, 9 Aug 2026 20:15:22 +0500 Subject: [PATCH] modified CaretNative --- CursorLang/Interop/CaretNative.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CursorLang/Interop/CaretNative.cs b/CursorLang/Interop/CaretNative.cs index d2188fa..76f9f51 100644 --- a/CursorLang/Interop/CaretNative.cs +++ b/CursorLang/Interop/CaretNative.cs @@ -65,12 +65,21 @@ internal static class CaretNative return caret; } + return Validate(caret, window, GetDpiForWindow(hwndFocus) / 96.0); + } + + /// + /// The same check over plain numbers: the input window bounds and the scale of + /// its monitor are already known. + /// + internal static PopupWindowNative.Rect? Validate( + PopupWindowNative.Rect caret, PopupWindowNative.Rect window, double scale) + { if (IsInside(caret, window)) { return caret; } - double scale = GetDpiForWindow(hwndFocus) / 96.0; var scaled = new PopupWindowNative.Rect { Left = (int)(caret.Left * scale), @@ -82,7 +91,7 @@ internal static class CaretNative return IsInside(scaled, window) ? scaled : null; } - private static bool IsInside(PopupWindowNative.Rect inner, PopupWindowNative.Rect outer) => + internal static bool IsInside(PopupWindowNative.Rect inner, PopupWindowNative.Rect outer) => inner.Left >= outer.Left && inner.Right <= outer.Right && inner.Top >= outer.Top && inner.Bottom <= outer.Bottom;