Subject: bug#79070: [PATCH] Fix macOS dictation post NSTextInputClient migration in v30

From: Eli Zaretskii <[email-masked]>
Date: Tue, 22 Jul 2025 16:10:13 +0300

> From: Alvaro Ramirez <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],
>   [email-masked],  [email-masked],  Stefan Kangas
>  <[email-masked]>
> Date: Tue, 22 Jul 2025 08:54:09 +0100
> 
> diff --git a/etc/PROBLEMS b/etc/PROBLEMS
> index 20fe9134da5..1323f02a1e9 100644
> --- a/etc/PROBLEMS
> +++ b/etc/PROBLEMS
> @@ -3566,6 +3566,14 @@ 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") ":"))
>  
> +** macOS text dictation isn't recognising keyboard shortcut
> +
> +There's a chance that microphone permission may have been rejected in the past.
> +
> +Try clearing this permission with:
> +
> +  tccutil reset Microphone org.gnu.Emacs
> +

This should explain better what are the indications of the problem.

> --- a/src/nsterm.m
> +++ b/src/nsterm.m
> @@ -7413,7 +7413,24 @@ - (NSRange)selectedRange
>  {
>    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);

Can we have a comment there explaining why this code is needed?