]> git.eshelyaron.com Git - emacs.git/commitdiff
Enabled macOS dictation post NSTextInputClient migration in v30
authorAlvaro Ramirez <me@xenodium.com>
Mon, 21 Jul 2025 11:53:50 +0000 (12:53 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Jul 2025 15:24:53 +0000 (17:24 +0200)
* src/nsterm.m (selectedRange): Implement to fix dictation.
* etc/NEWS: Announce regression fix.
* etc/PROBLEMS: Help users recover from rejected permission.

(cherry picked from commit 6e64e0bd26b6c0f1c4e90c9bc0df37a2a9ac72da)

etc/PROBLEMS
src/nsterm.m

index b8a60b7e4c2a142d147b1fb0b92337ff2679a6ce..5da83fefeb1df106a87548d4b5e084651cf34ffd 100644 (file)
@@ -3578,6 +3578,18 @@ file; for example:
       "/usr/local/opt/libgccjit/lib/gcc/11"
       "/usr/local/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0") ":"))
 
+** Text dictation doesn't work on macOS
+
+The indication is that the macOS keyboard shortcut for dictation is ignored.
+
+One reason for this is that the Emacs permissions for using the
+microphone were rejected in the past.  To reset the permissions, run
+this command:
+
+  tccutil reset Microphone org.gnu.Emacs
+
+Another reason may be an unsupported macOS version. For example: macOS 12.
+
 * Runtime problems specific to PGTK build
 
 ** Whether a display server is available cannot be automatically detected.
index 14f47973e542faa16b0283d21cf8796fcebee684..5b4067d3a0d4ae076c2773cd9a1b27172ef2d653 100644 (file)
@@ -7413,7 +7413,24 @@ ns_in_echo_area (void)
 {
   if (NS_KEYLOG)
     NSLog (@"selectedRange request");
-  return NSMakeRange (NSNotFound, 0);
+
+  struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
+  struct buffer *buf = XBUFFER (w->contents);
+  ptrdiff_t point = BUF_PT (buf);
+
+  if (NILP (BVAR (buf, mark_active)))
+    {
+      NSUInteger selection_location = point - BUF_BEGV (buf);
+      return NSMakeRange (selection_location, 0);
+    }
+
+  ptrdiff_t mark = marker_position (BVAR (buf, mark));
+  ptrdiff_t region_start = min (point, mark);
+  ptrdiff_t region_end = max (point, mark);
+  NSUInteger selection_location = region_start - BUF_BEGV (buf);
+  NSUInteger selection_length = region_end - region_start;
+
+  return NSMakeRange (selection_location, selection_length);
 }
 
 #if defined (NS_IMPL_COCOA) || GNUSTEP_GUI_MAJOR_VERSION > 0 || \