Subject: bug#38013: [PATCH] Rectangular region selection with mouse

From: Mattias Engdegård <[email-masked]>
Date: Sun, 10 Nov 2019 14:49:11 +0100

9 nov. 2019 kl. 21.04 skrev Eli Zaretskii <[email-masked]>:

> I still see a 1-pixel thin "region" sometimes, which causes the text
> to move horizontally.

Such 'thin' regions (0 cells wide) are legitimate and useful for marking a vertical span of insertion points. For example, they can be used with 'C-x r t' or 'C-x r N'. They are produced in keyboard-based rectangle selection (C-x SPC C-n C-n C-n) as well.

>  More importantly, if I drag the mouse through a
> TAB, it moves in jumps of several columns, not one column at a time.

The reason is that 'mouse-movement' events are not generated as long as the mouse stays within the same glyph, and a tab counts as a (suitably wide) single glyph. It can be worked around by zig-zagging the mouse a bit, but I agree it's untidy.

Fixing this requires some work on the lower-level plumbing which I'd hoped to avoid. One possibility is to add a global flag that forces 'remember_mouse_glyph' to consider all text glyphs to have nominal char width, or just zero width.

Or even simpler: assuming that STRETCH_GLYPHS are mostly tabs, we can treat them as image glyphs for 'remember_mouse_glyph' purposes. What about:

--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2572,7 +2572,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
 
 	  if (g < end)
 	    {
-	      if (g->type == IMAGE_GLYPH)
+	      if (g->type == IMAGE_GLYPH || g->type == STRETCH_GLYPH)