fix timestamp selection handling

This commit is contained in:
deepend committed 2026-10-25 04:46:53 -06:00
1 parent 6e5ed9270e
commit 1d24941ed5
1 file changed
+26 -7
+26 -7
View File
@@ -2119,8 +2119,19 @@ static gboolean
gtk_xtext_check_mark_stamp (GtkXText *xtext, GdkModifierType mask) gtk_xtext_check_mark_stamp (GtkXText *xtext, GdkModifierType mask)
{ {
gboolean redraw = FALSE; gboolean redraw = FALSE;
gboolean selecting_stamp = FALSE;
if ((mask & STATE_SHIFT || prefs.hex_text_autocopy_stamp) /* A drag into the timestamp column deliberately includes the stamp.
Ordinary message selection does not. Only indented views have a
separate timestamp column; inline stamps are part of the text. */
if (xtext->button_down && xtext->buffer->time_stamp && xtext->auto_indent)
{
selecting_stamp =
(xtext->select_start_x >= 0 && xtext->select_start_x < xtext->stamp_width) ||
(xtext->select_end_x >= 0 && xtext->select_end_x < xtext->stamp_width);
}
if ((mask & STATE_SHIFT || prefs.hex_text_autocopy_stamp || selecting_stamp)
&& (!prefs.hex_stamp_text || prefs.hex_text_indent)) && (!prefs.hex_stamp_text || prefs.hex_text_indent))
{ {
if (!xtext->mark_stamp) if (!xtext->mark_stamp)
@@ -2254,13 +2265,15 @@ gtk_xtext_motion_notify (GtkWidget * widget, GdkEventMotion * event)
if (xtext->button_down) if (xtext->button_down)
{ {
redraw = gtk_xtext_check_mark_stamp (xtext, mask); /* Update the pointer position before deciding whether this drag
gtk_grab_add (widget); explicitly includes the timestamp column. */
xtext->select_end_x = x; xtext->select_end_x = x;
xtext->select_end_y = y; xtext->select_end_y = y;
redraw = gtk_xtext_check_mark_stamp (xtext, mask);
gtk_grab_add (widget);
gtk_xtext_selection_update (xtext, event, y, !redraw); gtk_xtext_selection_update (xtext, event, y, !redraw);
/* user has pressed or released SHIFT, must redraw entire selection */ /* SHIFT or timestamp inclusion changed: redraw the full selection. */
if (redraw) if (redraw)
{ {
xtext->force_stamp = TRUE; xtext->force_stamp = TRUE;
@@ -2711,8 +2724,8 @@ gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret)
if (!first) if (!first)
g_string_append_c (text, '\n'); g_string_append_c (text, '\n');
first = FALSE; first = FALSE;
if (ent->mark_end > ent->mark_start) /* A selection entirely within the timestamp column has no
{ message bytes selected, but should still copy the stamp. */
if (ent->mark_start == 0 && xtext->mark_stamp && ent->stamp_len == 0) if (ent->mark_start == 0 && xtext->mark_stamp && ent->stamp_len == 0)
{ {
char *stamp; char *stamp;
@@ -2720,10 +2733,10 @@ gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret)
g_string_append_len (text, stamp, len); g_string_append_len (text, stamp, len);
g_free (stamp); g_free (stamp);
} }
if (ent->mark_end > ent->mark_start)
g_string_append_len (text, (char *)ent->str + ent->mark_start, g_string_append_len (text, (char *)ent->str + ent->mark_start,
ent->mark_end - ent->mark_start); ent->mark_end - ent->mark_start);
} }
}
if (ent == buf->last_ent_end) if (ent == buf->last_ent_end)
break; break;
} }
@@ -3974,6 +3987,12 @@ gtk_xtext_render_stamp (GtkXText * xtext, textentry * ent,
ent->mark_end = -1; ent->mark_end = -1;
} }
} }
else
{
/* Message selection offsets must not select unrelated stamp bytes. */
ent->mark_start = -1;
ent->mark_end = -1;
}
y = (xtext->fontsize * line) + xtext->font->ascent - xtext->pixel_offset; y = (xtext->fontsize * line) + xtext->font->ascent - xtext->pixel_offset;
gtk_xtext_render_str (xtext, y, ent, text, len, gtk_xtext_render_str (xtext, y, ent, text, len,