Grouping over open groups nests them instead of emptying them
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
edb49fce27
commit
9a0d97e924
2 changed files with 34 additions and 3 deletions
|
|
@ -389,6 +389,20 @@ func _test_nested() -> void:
|
|||
var back := TowerBoard.new()
|
||||
back.load_dict(d)
|
||||
_check(back.groups.size() == main.data.groups.size(), "groups survive saving")
|
||||
# A box over an open group selects its cards, not always the frame:
|
||||
# grouping then nests the open group instead of emptying it.
|
||||
main.clear_selection()
|
||||
_check(not inner.collapsed, "(the inner group is open)")
|
||||
for tid: String in inner.members:
|
||||
main.editing.toggle_selected(tid)
|
||||
main.editing.toggle_selected("loose")
|
||||
var kept := inner.members.duplicate()
|
||||
var wrapper := main.grouping.group_selection()
|
||||
await _frames(3)
|
||||
_check(wrapper != null and inner.parent == wrapper.id and inner.members == kept, "selecting every card of an open group nests the group")
|
||||
_eq(wrapper.members if wrapper else [], ["loose"], "and only the loose card joins the new group directly")
|
||||
main.ungroup(wrapper.id)
|
||||
await _frames(3)
|
||||
|
||||
|
||||
func _shown(tid: String) -> bool:
|
||||
|
|
|
|||
|
|
@ -190,11 +190,18 @@ func group_selection() -> TableGroup:
|
|||
if m.selection.has(t.id):
|
||||
ids.append(t.id)
|
||||
# Selected groups go inside the new group; cards they carry move with them.
|
||||
# An open group whose cards are all selected counts as selected too, so a
|
||||
# box drawn over open groups nests them instead of emptying them.
|
||||
var picked := m.selecting.groups.duplicate()
|
||||
for group in m.data.groups:
|
||||
var cards_inside := m.data.tables_in(group.id)
|
||||
if not group.collapsed and not cards_inside.is_empty() and cards_inside.all(func(tid: String) -> bool: return m.selection.has(tid)):
|
||||
picked[group.id] = true
|
||||
var inner: Array[String] = []
|
||||
for gid: String in m.selecting.groups:
|
||||
if m.data.get_group(gid) and not m.selecting.covers_group(gid):
|
||||
for gid: String in picked:
|
||||
if m.data.get_group(gid) and not _inside_picked(m.data.get_group(gid).parent, picked):
|
||||
inner.append(gid)
|
||||
ids = ids.filter(func(tid: String) -> bool: return not m.selecting.covers(tid))
|
||||
ids = ids.filter(func(tid: String) -> bool: return not _inside_picked(m.data.group_of(tid).id if m.data.group_of(tid) else "", picked))
|
||||
if ids.is_empty() and inner.is_empty():
|
||||
m.toast("Select some cards or groups first: drag a box around them, or Ctrl-click their headers")
|
||||
return null
|
||||
|
|
@ -220,6 +227,16 @@ func group_selection() -> TableGroup:
|
|||
return g
|
||||
|
||||
|
||||
## True when `gid` or a group around it is in `picked` (gid -> true).
|
||||
func _inside_picked(gid: String, picked: Dictionary) -> bool:
|
||||
var group := m.data.get_group(gid)
|
||||
while group != null:
|
||||
if picked.has(group.id):
|
||||
return true
|
||||
group = m.data.get_group(group.parent)
|
||||
return false
|
||||
|
||||
|
||||
## The group the new group goes in: the one every picked card and group
|
||||
## already shares, else the spread itself ("").
|
||||
func _common_parent(ids: Array[String], inner: Array[String]) -> String:
|
||||
|
|
|
|||
Loading…
Reference in a new issue