From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Moritz Maxeiner Newsgroups: gmane.emacs.devel Subject: Re: Moving point after character when clicking latter half of it Date: Mon, 10 Jul 2023 22:02:23 +0200 Message-ID: <3431515.QJadu78ljV@anduin> References: <2255158.iZASKD2KPV@silef> <3255279.aeNJFYEL58@silef> <83ttuc7x3k.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1863620.CQOukoFCf9" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34344"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 10 22:03:27 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 1qIx6V-0008m5-90 for ged-emacs-devel@m.gmane-mx.org; Mon, 10 Jul 2023 22:03:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIx5c-0006Ol-6z; Mon, 10 Jul 2023 16:02:32 -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 1qIx5Z-0006O5-P2 for emacs-devel@gnu.org; Mon, 10 Jul 2023 16:02:30 -0400 Original-Received: from nephos.ucw.sh ([138.201.61.214] helo=mail.ucw.sh) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIx5X-0002MS-FT; Mon, 10 Jul 2023 16:02:29 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.ucw.sh (Postfix) with ESMTP id D374B97A99; Mon, 10 Jul 2023 22:02:24 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.ucw.sh Original-Received: from mail.ucw.sh ([127.0.0.1]) by localhost (mail.ucw.sh [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 6GZ1U75eYjF7; Mon, 10 Jul 2023 22:02:24 +0200 (CEST) Original-Received: from anduin.localnet (p200300d29747ec8d3033d66cdfd84b91.dip0.t-ipconnect.de [IPv6:2003:d2:9747:ec8d:3033:d66c:dfd8:4b91]) (Authenticated sender: mm@ucw.sh) by mail.ucw.sh (Postfix) with ESMTPSA; Mon, 10 Jul 2023 22:02:24 +0200 (CEST) In-Reply-To: <83ttuc7x3k.fsf@gnu.org> Received-SPF: pass client-ip=138.201.61.214; envelope-from=mm@ucw.sh; helo=mail.ucw.sh X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:307732 Archived-At: This is a multi-part message in MIME format. --nextPart1863620.CQOukoFCf9 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Thank you for your suggestions (I've not quoted them in this reply for brevity). Unless I've overlooked something I've implemented them all, except for the etc/NEWS entry. On Monday 10 July 2023 14:46:39 CEST Eli Zaretskii wrote: > It should also be called out in etc/NEWS. I agree, but I feel this should be done in the last iteration of the patch, once all other changes are done. Which leads me to the next point: I had to add another piece of code to src/xterm.c, because while text selection via mouse dragging did automatically factor in the new optional behavior after releasing the mouse, it did not update the highlighted / selected region, as that requires mouse-movement events to be triggered, which are picked up in mouse.el via mouse-drag-track, which then updated the highlighted region. That event, however, is only triggered by leaving the previous glyph, so we need to trigger it while still being on the glyph. I tried sending the event only when crossing the vertical midline of the glyph, but for a reason unknown to me, sending the event only once did not result in the highlight being updated when dragging the mouse to the right, only to the left. As a workaround, I now trigger the event always while dragging with the optional behavior on. If there is a more elegant solution I don't see I'd welcome it. For now the overhead doesn't seem noticeable in practice. --nextPart1863620.CQOukoFCf9 Content-Disposition: attachment; filename="emacs-29-move_it_in_display_line_to-nextglyphafterhalf-poc-0.4.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="emacs-29-move_it_in_display_line_to-nextglyphafterhalf-poc-0.4.patch" diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 054683d7cf6..489471f8eab 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -231,6 +231,7 @@ minibuffer-prompt-properties--setter (inverse-video display boolean) (visible-bell display boolean) (no-redraw-on-reenter display boolean) + (mouse-click-prefer-closest-char display boolean) ;; doc.c (text-quoting-style display diff --git a/src/dispnew.c b/src/dispnew.c index 65d9cf9b4e1..5fcecd5811d 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5611,6 +5611,15 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p argument is ZV to prevent move_it_in_display_line from matching based on buffer positions. */ move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X); + if (mouse_click_prefer_closest_char) + { + int next_x = it.current_x + it.pixel_width; + int before_dx = to_x - it.current_x; + int after_dx = next_x - to_x; + if (before_dx > after_dx) + move_it_in_display_line (&it, ZV, next_x, MOVE_TO_X); + } + bidi_unshelve_cache (itdata, 0); Fset_buffer (old_current_buffer); @@ -6788,6 +6797,12 @@ syms_of_display (void) DEFVAR_BOOL ("cursor-in-echo-area", cursor_in_echo_area, doc: /* Non-nil means put cursor in minibuffer, at end of any message there. */); + DEFVAR_BOOL ("mouse-click-prefer-closest-char", mouse_click_prefer_closest_char, + doc: /* Non-nil means mouse click prefers the closest glyph as point. +When this is non-nil, clicking inside a glyph picks up the next glyph if the click +is closer to it then half the width of the clicked glyph. */); + mouse_click_prefer_closest_char = false; + DEFVAR_LISP ("glyph-table", Vglyph_table, doc: /* Table defining how to output a glyph code to the frame. If not nil, this is a vector indexed by glyph code to define the glyph. diff --git a/src/xterm.c b/src/xterm.c index 5840b15bcb7..44dcc8b1761 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -14206,11 +14206,13 @@ x_note_mouse_movement (struct frame *frame, const XMotionEvent *event, } - /* Has the mouse moved off the glyph it was on at the last sighting? */ + /* Has the mouse moved off the glyph it was on at the last sighting? + Is the mouse being dragged while we need to keep point to the nearest glyph? */ r = &dpyinfo->last_mouse_glyph; if (frame != dpyinfo->last_mouse_glyph_frame || event->x < r->x || event->x >= r->x + r->width - || event->y < r->y || event->y >= r->y + r->height) + || event->y < r->y || event->y >= r->y + r->height + || mouse_click_prefer_closest_char && EQ (track_mouse, Qdrag_tracking)) { frame->mouse_moved = true; frame->last_mouse_device = device; @@ -31705,4 +31707,6 @@ syms_of_xterm (void) If that is still too slow, setting this variable to the symbol `really-fast' will make Emacs return only cached values. */); Vx_use_fast_mouse_position = Qnil; + + DEFSYM (Qdrag_tracking, "drag-tracking"); } --nextPart1863620.CQOukoFCf9--