all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Moritz Maxeiner <mm@ucw.sh>
Cc: emacs-devel@gnu.org
Subject: Re: Moving point after character when clicking latter half of it
Date: Mon, 10 Jul 2023 15:46:39 +0300	[thread overview]
Message-ID: <83ttuc7x3k.fsf@gnu.org> (raw)
In-Reply-To: <3255279.aeNJFYEL58@silef> (message from Moritz Maxeiner on Sun,  09 Jul 2023 23:47:51 +0200)

> From: Moritz Maxeiner <mm@ucw.sh>
> Cc: emacs-devel@gnu.org
> Date: Sun, 09 Jul 2023 23:47:51 +0200
> 
> > Basically, you need to examine it.current_x after the last call to
> > move_it_in_display_line returns, and if it is closer to
> > to_x+it.pixel_width than to to_x, call move_it_in_display_line again
> > to get to to_x+it.pixel_width.
> 
> Thanks, I've implemented something along those lines. Same source position,
> but the check is if to_x exceeds half of the selected display element's width
> and if so rerun move_it_in_display_line at it.current_x + it.pixel_width
> (so first pixel of the next display element).
> Running it at to_x+it.pixel_width might run into trouble if the current display
> element is a lot wider than the one after it.

OK, but would you please rewrite the condition to avoid unnecessary
floating-point computations?  There's no need to compute half of
pixel_width, only to see if to_x is closer to the next display element
than it is to the current display element.

> I've also added an option mouse_point_alternate (temporary name, didn't know
> what else to call it, open to suggestions) to enable it. It defaults to off.

I can suggest mouse-click-prefer-closest-char.

> But I have to say it feels wasteful to call the function twice instead of having
> it deal with it "correctly" the first time around with an option.

That's because you aren't accustomed with this kind of code.  We do
this all the time, and there's nothing wasteful about it.

>  #include "sysstdio.h"
>  #include <stdlib.h>
> +#include <math.h>
>  #include <unistd.h>

This will be unnecessary once you get rid of the FP calculations.

>    move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X);
> +  if (mouse_point_alternate && to_x > it.current_x + ceil (it.pixel_width / 2.0))
> +    move_it_in_display_line (&it, ZV, it.current_x + it.pixel_width, MOVE_TO_X);

These two lines are too long, please break them in two.

> @@ -6468,6 +6472,7 @@ init_display_interactive (void)
>  
>    inverse_video = 0;
>    cursor_in_echo_area = false;
> +  mouse_point_alternate = false;

This initialization should be immediately after the DEFVAR.

> +  DEFVAR_BOOL ("mouse-point-alternate", mouse_point_alternate,
> +	       doc: /* Non-nil means use alternate mode for mouse click selection of point.

The first line of the doc string will be more useful if it says
something about the effect of the option.  Something like this,
perhaps:

  Non-nil means mouse click prefers the closest glyph.

> +In alternate mode, if the clicked x coordinate exceeds half of the selected
> +display element's width, put point after it.  */);

This describes the effect in terms of the implementation more than in
terms of UX.  How about

  When this is non-nil, clicking inside a glyph picks up the next
  glyph if the click is closer to it than half the width of the
  clicked glyph.

This variable should be added to cus-start.el, with a suitable
customization form, since this is a user option.  It should also be
called out in etc/NEWS.

Thanks.



  reply	other threads:[~2023-07-10 12:46 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-08 21:01 Moving point after character when clicking latter half of it Moritz Maxeiner
2023-07-09  6:35 ` Eli Zaretskii
2023-07-09 12:44   ` Moritz Maxeiner
2023-07-09 13:23     ` Eli Zaretskii
2023-07-09 13:51       ` Moritz Maxeiner
2023-07-09 14:14         ` Eli Zaretskii
2023-07-09 21:47           ` Moritz Maxeiner
2023-07-10 12:46             ` Eli Zaretskii [this message]
2023-07-10 14:43               ` [External] : " Drew Adams
2023-07-10 20:02               ` Moritz Maxeiner
2023-07-11 12:29                 ` Eli Zaretskii
2023-07-11 13:10                   ` Po Lu
2023-07-11 18:01                     ` Moritz Maxeiner
2023-07-12  0:52                       ` Po Lu
2023-07-12 19:58                         ` Moritz Maxeiner
2023-07-12 21:17                           ` Yuan Fu
2023-07-12 21:36                             ` Moritz Maxeiner
2023-07-12 22:08                               ` Yuan Fu
2023-07-13  5:27                             ` Eli Zaretskii
2023-07-13 23:25                               ` Yuan Fu
2023-07-13  0:31                           ` Po Lu
2023-07-13  8:47                           ` Eli Zaretskii
2023-07-21 19:04                             ` Moritz Maxeiner
2023-07-21 23:57                               ` Po Lu
2023-07-22  5:41                                 ` Eli Zaretskii
2023-07-22 10:07                                   ` Moritz Maxeiner
2023-07-22 11:31                                     ` Po Lu
2023-07-22 12:51                                     ` Eli Zaretskii
2023-07-22 15:28                                       ` Moritz Maxeiner
2023-07-22 15:51                                         ` Eli Zaretskii
2023-07-22 15:59                                           ` Moritz Maxeiner
2023-07-22 16:34                                             ` Eli Zaretskii
2023-07-22 19:10                                             ` Yuan Fu
2023-07-09 13:58       ` Yuri Khan
2023-07-09 12:40 ` Benjamin Riefenstahl
2023-07-09 12:47   ` Moritz Maxeiner
2023-07-09 13:37     ` Benjamin Riefenstahl
2023-07-09 15:15   ` [External] : " Drew Adams
2023-07-09 15:33     ` Moritz Maxeiner
2023-07-09 16:06       ` Drew Adams
2023-07-09 16:21       ` Brian Cully via Emacs development discussions.
2023-07-09 18:01         ` Jens Schmidt
2023-07-09 16:43       ` [External] : " Eli Zaretskii
2023-07-12 18:21     ` Benjamin Riefenstahl
2023-07-12 18:32       ` Eli Zaretskii
     [not found] ` <12248204.O9o76ZdvQC@anduin>
     [not found]   ` <87ilac2kla.fsf@yahoo.com>
2023-07-22 14:48     ` Moritz Maxeiner
2023-07-22 15:26       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83ttuc7x3k.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mm@ucw.sh \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.