From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Moving point after character when clicking latter half of it Date: Mon, 10 Jul 2023 15:46:39 +0300 Message-ID: <83ttuc7x3k.fsf@gnu.org> References: <2255158.iZASKD2KPV@silef> <4513163.LvFx2qVVIh@anduin> <83edlh9npt.fsf@gnu.org> <3255279.aeNJFYEL58@silef> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31621"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Moritz Maxeiner Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 10 14:47:19 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qIqIR-00081V-NL for ged-emacs-devel@m.gmane-mx.org; Mon, 10 Jul 2023 14:47:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIqHh-0001W7-9t; Mon, 10 Jul 2023 08:46:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIqHf-0001Vy-MB for emacs-devel@gnu.org; Mon, 10 Jul 2023 08:46:31 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIqHe-0002WJ-JP; Mon, 10 Jul 2023 08:46:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=zAauoCZLSSHFfm1z7wB91GQlmLxxrLZp/U7A8S2wHUI=; b=jUw2FNmtl+hg cC6SEbQJezNEXLS0OlYXmTrFWYop30AdtJAnpsBZg6sEcDtfh5anEeCGWI5rOGTY1LS2sFcG+QOCc xbrLAUdi7E96DfEAL5R9fYMw0hs1cEFbaIOFftMA0uRclQ9yeUNE+uSRSJA6LyGlM5nKpVesY1WLQ 2NDTCxEIC0iKVOWBVhHyr9o9wybg+Bmj2FgUaDVYFhaX6W73eUjs8zn+U7qoYO+GF/mGwxk+V4Nas ZtM8E3tkY8fX9FU063VETrQihn76/ssVLgjm8CELXuLJoplip0Bqj55ph8ANaAm8hwSdo51jQ0QZK 37puoqrx1Yve10HcjqI08A==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIqHd-0002CR-W8; Mon, 10 Jul 2023 08:46:30 -0400 In-Reply-To: <3255279.aeNJFYEL58@silef> (message from Moritz Maxeiner on Sun, 09 Jul 2023 23:47:51 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:307717 Archived-At: > From: Moritz Maxeiner > 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 > +#include > #include 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.