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"); }