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(i)local k={Items=Support.CloneTable(Selection.Items);CurrentParents=Support.GetListMembers(Selection.Items,"\080\097\114\101\110\116")}function k.Unapply(i)SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",i.Items,i.CurrentParents)SyncAPI:Invoke("\082\101\109\111\118\101",{i.NewParent})Selection.Replace(i.Items)end function k.Apply(i)SyncAPI:Invoke("\085\110\100\111\082\101\109\111\118\101",{i.NewParent})SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",i.Items,i.NewParent)Selection.Replace({i.NewParent})end k.NewParent=SyncAPI:Invoke("\067\114\101\097\116\101\071\114\111\117\112",i,GetHighestParent(k.Items),k.Items)History.Add(k)Selection.Replace({k.NewParent})end function UngroupSelection()local i={Selection=Selection.Items}function i.Unapply(i)SyncAPI:Invoke("\085\110\100\111\082\101\109\111\118\101",i.Groups)for k,b in ipairs(i.GroupChildren)do coroutine.resume(coroutine.create(function()SyncAPI:Invoke("\083\101\116\080\097\114\101\110\116",b,i.Groups[k])end))end Selection.Replace(i.Selection)end function i.Apply(i)i.Groups={}for k,b in ipairs(i.Selection)do if b:IsA("\077\111\100\101\108")or b:IsA("\070\111\108\100\101\114")then i.Groups[#i.Groups+1]=b end end i.GroupParents=Support.GetListMembers(i.Groups,"\080\097\114\101\110\116")i.GroupChildren=SyncAPI:Invoke("\085\110\103\114\111\117\112",i.Groups)local k=Support.CloneTable(i.Selection)for i,b in pairs(i.GroupChildren)do for i,b in ipairs(b)do k[#k+1]=b end end Selection.Replace(k)end i:Apply()History.Add(i)end

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
