From c5d08b1229004e21062c23ca83fb03c2c8df2df6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 2 Oct 2026 12:35:46 +0000 Subject: [PATCH] nemo-icon-container.c: Don't relayout icon view for the whole rename. GtkScrolledWindow toggles scrollbars when the view is sized so the icons only just need a bar. Each keystroke changes the rename label's requisition and repeats that allocation. Relayout then moves the icon and icon_set_position() commits the rename, so every key acts like Enter. The 2018 workaround only skipped the first allocation of a rename. Skip relayout for the whole session and run a deferred one when it ends. Prepared by a Cursor cloud coding agent (an automated bot, not a human maintainer) on behalf of a Linux Mint user. That person encountered this bug and asked the agent to investigate and fix it. Base model: Grok 4.7. https://github.com/linuxmint/nemo/issues/3155 https://github.com/linuxmint/nemo/issues/3755 Co-authored-by: Roland de Boer --- libnemo-private/nemo-icon-container.c | 38 +++++++++++++++++++-------- libnemo-private/nemo-icon-private.h | 6 ++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/libnemo-private/nemo-icon-container.c b/libnemo-private/nemo-icon-container.c index c4eea668be..5cf0e2e45b 100644 --- a/libnemo-private/nemo-icon-container.c +++ b/libnemo-private/nemo-icon-container.c @@ -2848,13 +2848,20 @@ size_allocate (GtkWidget *widget, need_layout_redone = FALSE; } - if (is_renaming (container)) { - container->details->renaming_allocation_count++; - - if (container->details->renaming_allocation_count == 1) { - need_layout_redone = FALSE; - } - } + /* Scrollbar show/hide at the fit threshold allocates this view at + * two widths. Entering rename mode hits that once; the 2018 + * workaround skipped only the first allocation. Each keystroke + * changes the editable label's requisition and repeats the pair. + * A later allocation still relayouts, icon_set_position() sees the + * icon move, and the rename is committed. Every key acts like Enter. + * Skip relayout for the whole session and apply it once rename ends. + */ + if (is_renaming (container)) { + if (need_layout_redone) { + container->details->relayout_deferred_during_rename = TRUE; + } + need_layout_redone = FALSE; + } GTK_WIDGET_CLASS (nemo_icon_container_parent_class)->size_allocate (widget, allocation); @@ -4996,7 +5003,7 @@ nemo_icon_container_init (NemoIconContainer *container) details->skip_rename_on_release = FALSE; details->dnd_grid = NULL; details->current_selection_count = -1; - details->renaming_allocation_count = 0; + details->relayout_deferred_during_rename = FALSE; details->update_visible_icons_id = 0; details->ok_to_load_deferred_attrs = FALSE; @@ -7072,7 +7079,7 @@ nemo_icon_container_start_renaming_selected_item (NemoIconContainer *container, nemo_icon_container_update_icon (container, icon); - details->renaming_allocation_count = 0; + details->relayout_deferred_during_rename = FALSE; /* We are in renaming mode */ details->renaming = TRUE; @@ -7101,11 +7108,18 @@ nemo_icon_container_end_renaming_mode (NemoIconContainer *container, gboolean co { NemoIcon *icon; const char *changed_text = NULL; + gboolean relayout_deferred; + + relayout_deferred = container->details->relayout_deferred_during_rename; + container->details->relayout_deferred_during_rename = FALSE; set_pending_icon_to_rename (container, NULL); icon = nemo_icon_container_get_icon_being_renamed (container); if (icon == NULL) { + if (relayout_deferred) { + schedule_redo_layout (container); + } return; } @@ -7113,8 +7127,6 @@ nemo_icon_container_end_renaming_mode (NemoIconContainer *container, gboolean co container->details->renaming = FALSE; nemo_icon_canvas_item_set_renaming (icon->item, FALSE); - container->details->renaming_allocation_count = 0; - if (commit) { set_pending_icon_to_reveal (container, icon); } @@ -7138,6 +7150,10 @@ nemo_icon_container_end_renaming_mode (NemoIconContainer *container, gboolean co g_free (container->details->original_text); nemo_icon_container_unfreeze_updates (container); + + if (relayout_deferred) { + schedule_redo_layout (container); + } } void diff --git a/libnemo-private/nemo-icon-private.h b/libnemo-private/nemo-icon-private.h index b322292d01..49735834eb 100644 --- a/libnemo-private/nemo-icon-private.h +++ b/libnemo-private/nemo-icon-private.h @@ -245,7 +245,11 @@ struct NemoIconContainerDetails { int size_allocation_count; guint size_allocation_count_id; - int renaming_allocation_count; + + /* A size_allocate during rename needed a relayout. Icon positions + * are left alone until renaming ends, so scrollbar show/hide does + * not commit the rename. */ + gboolean relayout_deferred_during_rename; /* Is the container fixed or resizable */ gboolean is_fixed_size;