function Window.LoseFocus(o,H)local M=Entry.TextBox.Text o:ClearHistoryState()if Gui.Visible and not GuiService.MenuIsOpen then Entry.TextBox:CaptureFocus()elseif GuiService.MenuIsOpen and Gui.Visible then o:Hide()end if H and o.Valid then wait()o:SetEntryText("")o.ProcessEntry(M)elseif H then o:AddLine(o._errorText,Color3.fromRGB(255,153,153))end end function Window.TraverseHistory(o,H)local M=o.Cmdr.Dispatcher:GetHistory()if o.HistoryState==nil then o.HistoryState={Position=#M+1;InitialText=o:GetEntryText()}end o.HistoryState.Position=math.clamp(o.HistoryState.Position+H,1,#M+1)o:SetEntryText(o.HistoryState.Position==#M+1 and o.HistoryState.InitialText or M[o.HistoryState.Position])end function Window.ClearHistoryState(H)H.HistoryState=nil end function Window.SelectVertical(o,H)if o.AutoComplete:IsVisible()and not o.HistoryState then o.AutoComplete:Select(H)else o:TraverseHistory(H)end end local H=0 local o=0

function Window:LoseFocus(submit)
	local text = Entry.TextBox.Text

	self:ClearHistoryState()

	if Gui.Visible and not GuiService.MenuIsOpen then
		-- self:SetEntryText("")
		Entry.TextBox:CaptureFocus()
	elseif GuiService.MenuIsOpen and Gui.Visible then
		self:Hide()
	end

	if submit and self.Valid then
		wait()
		self:SetEntryText("")
		self.ProcessEntry(text)
	elseif submit then
		self:AddLine(self._errorText, Color3.fromRGB(255, 153, 153))
	end
end

function Window:TraverseHistory(delta)
	local history = self.Cmdr.Dispatcher:GetHistory()

	if self.HistoryState == nil then
		self.HistoryState = {
			Position = #history + 1;
			InitialText = self:GetEntryText();
		}
	end

	self.HistoryState.Position = math.clamp(self.HistoryState.Position + delta, 1, #history + 1)

	self:SetEntryText(
		self.HistoryState.Position == #history + 1
			and self.HistoryState.InitialText
			or history[self.HistoryState.Position]
	)
end

function Window:ClearHistoryState()
	self.HistoryState = nil
end

function Window:SelectVertical(delta)
	if self.AutoComplete:IsVisible() and not self.HistoryState then
		self.AutoComplete:Select(delta)
	else
		self:TraverseHistory(delta)
	end
end

local lastPressTime = 0
local pressCount = 0