From: Alvaro Ramirez Date: Mon, 21 Jul 2025 11:53:50 +0000 (+0100) Subject: Enabled macOS dictation post NSTextInputClient migration in v30 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f38b45e808dc6d418c03725077d21e8a269ea082;p=emacs.git Enabled macOS dictation post NSTextInputClient migration in v30 * 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) --- diff --git a/etc/PROBLEMS b/etc/PROBLEMS index b8a60b7e4c2..5da83fefeb1 100644 --- a/etc/PROBLEMS +++ b/etc/PROBLEMS @@ -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. diff --git a/src/nsterm.m b/src/nsterm.m index 14f47973e54..5b4067d3a0d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -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 || \