if Mode=="\084\111\111\108"then AssignHotkey({"\076\101\102\116\067\111\110\116\114\111\108","\076\101\102\116\066\114\097\099\107\101\116"},Support.Call(Targeting.SelectSiblings,false,false))AssignHotkey({"\082\105\103\104\116\067\111\110\116\114\111\108";"\076\101\102\116\066\114\097\099\107\101\116"},Support.Call(Targeting.SelectSiblings,false,false))AssignHotkey({"\076\101\102\116\067\111\110\116\114\111\108","\082"},Support.Call(Selection.Clear,true))AssignHotkey({"\082\105\103\104\116\067\111\110\116\114\111\108","\082"},Support.Call(Selection.Clear,true))end function GroupSelection(B)local i={Items=Support.CloneTable(Selection.Items),CurrentParents=Support.GetListMembers(Selection.Items,"\080\097\114\101\110\116")}function i.Unapply(B)SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",B.Items,B.CurrentParents)SyncAPI:Invoke("\082\101\109\111\118\101",{B.NewParent})Selection.Replace(B.Items)end function i.Apply(B)SyncAPI:Invoke("\085\110\100\111\082\101\109\111\118\101",{B.NewParent})SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",B.Items,B.NewParent)Selection.Replace({B.NewParent})end i.NewParent=SyncAPI:Invoke("\067\114\101\097\116\101\071\114\111\117\112",B,GetHighestParent(i.Items),i.Items)History.Add(i)Selection.Replace({i.NewParent})end function UngroupSelection()local B={Selection=Selection.Items}function B.Unapply(B)SyncAPI:Invoke("\085\110\100\111\082\101\109\111\118\101",B.Groups)for i,e in ipairs(B.GroupChildren)do coroutine.resume(coroutine.create(function()SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",e,B.Groups[i])end))end Selection.Replace(B.Selection)end function B.Apply(B)B.Groups={}for i,e in ipairs(B.Selection)do if e:IsA("\077\111\100\101\108")or e:IsA("\070\111\108\100\101\114")then B.Groups[#B.Groups+1]=e end end B.GroupParents=Support.GetListMembers(B.Groups,"\080\097\114\101\110\116")B.GroupChildren=SyncAPI:Invoke("\085\110\103\114\111\117\112",B.Groups)local i=Support.CloneTable(B.Selection)for B,e in pairs(B.GroupChildren)do for B,e in ipairs(e)do i[#i+1]=e end end Selection.Replace(i)end B:Apply()History.Add(B)end
-- If in-game, enable ctrl hotkeys for sibling selection & selection clearing
if Mode == "Tool" then
	AssignHotkey({ "LeftControl", "LeftBracket" }, Support.Call(Targeting.SelectSiblings, false, false))
	AssignHotkey({ "RightControl", "LeftBracket" }, Support.Call(Targeting.SelectSiblings, false, false))
	AssignHotkey({ "LeftControl", "R" }, Support.Call(Selection.Clear, true))
	AssignHotkey({ "RightControl", "R" }, Support.Call(Selection.Clear, true))
end

function GroupSelection(GroupType)
	-- Groups the selected items

	-- Create history record
	local HistoryRecord = {
		Items = Support.CloneTable(Selection.Items),
		CurrentParents = Support.GetListMembers(Selection.Items, "Parent"),
	}

	function HistoryRecord:Unapply()
		SyncAPI:Invoke("SetParent", self.Items, self.CurrentParents)
		SyncAPI:Invoke("Remove", { self.NewParent })
		Selection.Replace(self.Items)
	end

	function HistoryRecord:Apply()
		SyncAPI:Invoke("UndoRemove", { self.NewParent })
		SyncAPI:Invoke("SetParent", self.Items, self.NewParent)
		Selection.Replace({ self.NewParent })
	end

	-- Perform group creation
	HistoryRecord.NewParent =
		SyncAPI:Invoke("CreateGroup", GroupType, GetHighestParent(HistoryRecord.Items), HistoryRecord.Items)

	-- Register history record
	History.Add(HistoryRecord)

	-- Select new group
	Selection.Replace({ HistoryRecord.NewParent })
end

function UngroupSelection()
	-- Ungroups the selected groups

	-- Create history record
	local HistoryRecord = {
		Selection = Selection.Items,
	}

	function HistoryRecord:Unapply()
		SyncAPI:Invoke("UndoRemove", self.Groups)

		-- Reparent children
		for GroupId, Items in ipairs(self.GroupChildren) do
			coroutine.resume(coroutine.create(function()
				SyncAPI:Invoke("SetParent", Items, self.Groups[GroupId])
			end))
		end

		-- Reselect groups
		Selection.Replace(self.Selection)
	end

	function HistoryRecord:Apply()
		-- Get groups from selection
		self.Groups = {}
		for _, Item in ipairs(self.Selection) do
			if Item:IsA("Model") or Item:IsA("Folder") then
				self.Groups[#self.Groups + 1] = Item
			end
		end

		-- Perform ungrouping
		self.GroupParents = Support.GetListMembers(self.Groups, "Parent")
		self.GroupChildren = SyncAPI:Invoke("Ungroup", self.Groups)

		-- Get unpacked children
		local UnpackedChildren = Support.CloneTable(self.Selection)
		for GroupId, Children in pairs(self.GroupChildren) do
			for _, Child in ipairs(Children) do
				UnpackedChildren[#UnpackedChildren + 1] = Child
			end
		end

		-- Select unpacked items
		Selection.Replace(UnpackedChildren)
	end

	-- Perform action
	HistoryRecord:Apply()

	-- Register history record
	History.Add(HistoryRecord)
end
