From b536064882a4a436781a6c34122f8c919729a19c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 17 Mar 2018 16:09:53 +0200 Subject: [PATCH] Fix removing rooms --- view-main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/view-main.go b/view-main.go index 4696afb..57e5d6d 100644 --- a/view-main.go +++ b/view-main.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "sort" "strings" "time" "unicode" @@ -252,11 +253,17 @@ func (view *MainView) RemoveRoom(room string) { if !view.HasRoom(room) { return } - view.roomList.RemoveItem(view.currentRoomIndex) + removeIndex := 0 if view.CurrentRoomID() == room { + removeIndex = view.currentRoomIndex view.SwitchRoom(view.currentRoomIndex - 1) + } else { + removeIndex = sort.StringSlice(view.roomIDs).Search(room) } + view.roomList.RemoveItem(removeIndex) + view.roomIDs = append(view.roomIDs[:removeIndex], view.roomIDs[removeIndex+1:]...) view.roomView.RemovePage(room) + view.Render() } func (view *MainView) SetRoomList(rooms []string) {