From d2adf0501c22144cdd914d20b0a2a6a2a3f40c1f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 May 2024 20:45:51 -0700 Subject: [PATCH] macos: ime coordinate needs to be converted from view to window coords Fixes #1756 We previously converted from view to screen coordinates but if the view doesn't take up the full window then the view coordinates are wrong. We need to convert to window coordinates in the middle. --- macos/Sources/Ghostty/SurfaceView_AppKit.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 6f3c4a357..255248c61 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -971,11 +971,14 @@ extension Ghostty.SurfaceView: NSTextInputClient { // Ghostty coordinates are in top-left (0, 0) so we have to convert to // bottom-left since that is what UIKit expects - let rect = NSMakeRect(x, frame.size.height - y, 0, 0) + let viewRect = NSMakeRect(x, frame.size.height - y, 0, 0) + + // Convert the point to the window coordinates + let winRect = self.convert(viewRect, to: nil) // Convert from view to screen coordinates - guard let window = self.window else { return rect } - return window.convertToScreen(rect) + guard let window = self.window else { return winRect } + return window.convertToScreen(winRect) } func insertText(_ string: Any, replacementRange: NSRange) {