Preserve tile selection when toggling dynamic wrapping by MollahHamza · Pull Request #4385 · mapeditor/tiled (original) (raw)

Fixes #3949

Problem

When toggling "Dynamically Wrap Tiles" in the Tilesets dock or Tileset Editor, the current tile selection was being cleared. Since wrapping is purely a visual/layout option, the selection should be preserved.

Root Cause

TilesetModel::setColumnCountOverride() was using beginResetModel()/ endResetModel(), which causes Qt to unconditionally clear the selection model. This is the wrong mechanism here since only the column layout is changing, not the underlying tile data.

Fix

Switch to layoutAboutToBeChanged()/layoutChanged() with persistent index remapping. Before the column count changes, persistent indexes are captured and remapped to their new positions after the change, so the selection model correctly tracks the same tiles through the reflow.