]> git.eshelyaron.com Git - emacs.git/commitdiff
MacOS: Let EmacsView implement NSTextInputClient
authorGerd Möllmann <gerd@gnu.org>
Tue, 30 Jul 2024 05:47:44 +0000 (07:47 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 2 Aug 2024 09:56:26 +0000 (11:56 +0200)
* src/nsterm.h (@interface EmacsView): Implement NSTextInputClient protocol.
* src/nsterm.m: Implement required NSTextInputClient methods, forwarding
to existing NSTextInput methods.

(cherry picked from commit ceb5a1522270c41d0c9f5e6b52d61e3173f72f1d)

src/nsterm.h
src/nsterm.m

index e3f55c4e41c1a8718f45cd0cf1c519284d0c4905..a07829a36ec45e04fcf558838d9c753a540111b0 100644 (file)
@@ -463,7 +463,7 @@ enum ns_return_frame_mode
 @class EmacsLayer;
 
 #ifdef NS_IMPL_COCOA
-@interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
+@interface EmacsView : NSView <NSTextInput, NSTextInputClient, NSWindowDelegate>
 #else
 @interface EmacsView : NSView <NSTextInput>
 #endif
index 8a0c12c7369f6624b580502d8c2bd9e7b8c0de60..b56c587bc698ade0fa5080a4033e54a49402a3a7 100644 (file)
@@ -7032,9 +7032,48 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action)
   [nsEvArray removeObject: theEvent];
 }
 
+/***********************************************************************
+                          NSTextInputClient
+ ***********************************************************************/
 
-/* <NSTextInput> implementation (called through [super interpretKeyEvents:]).  */
+#ifdef NS_IMPL_COCOA
+
+- (void) insertText: (id) string
+   replacementRange: (NSRange) replacementRange
+{
+  if ([string isKindOfClass:[NSAttributedString class]])
+    string = [string string];
+  [self unmarkText];
+  [self insertText:string];
+}
+
+- (void) setMarkedText: (id) string
+        selectedRange: (NSRange) selectedRange
+      replacementRange: (NSRange) replacementRange
+{
+  [self setMarkedText: string selectedRange: selectedRange];
+}
+
+- (nullable NSAttributedString *)
+  attributedSubstringForProposedRange: (NSRange) range
+                         actualRange: (nullable NSRangePointer) actualRange
+{
+  return nil;
+}
+
+- (NSRect) firstRectForCharacterRange: (NSRange) range
+                         actualRange: (nullable NSRangePointer) actualRange
+{
+  return NSZeroRect;
+}
 
+#endif /* NS_IMPL_COCOA */
+
+/***********************************************************************
+                             NSTextInput
+ ***********************************************************************/
+
+/* <NSTextInput> implementation (called through [super interpretKeyEvents:]).  */
 
 /* <NSTextInput>: called when done composing;
    NOTE: also called when we delete over working text, followed