Everything is no longer broken

This commit is contained in:
Tulir Asokan
2018-04-24 16:51:40 +03:00
parent fcd9a932cb
commit e64df67ec3
10 changed files with 77 additions and 40 deletions

View File

@ -183,7 +183,8 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction ifc.Messag
} else if oldMsg != nil {
view.replaceBuffer(oldMsg, message)
} else {
view.replaceBuffer(message, message)
debug.Print("Unexpected AddMessage() call: Direction is not append or prepend, but message is new.")
debug.PrintStack()
}
view.messageIDs[message.ID()] = message
@ -232,7 +233,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
}
if start == -1 {
debug.Print("Called replaceBuffer() with message that was not in the buffer:", original)
debug.Print("Called replaceBuffer() with message that was not in the buffer:", original.ID())
view.appendBuffer(new)
return
}

View File

@ -73,7 +73,13 @@ func (msg *BaseTextMessage) calculateBufferWithText(text tstring.TString, width
matches := boundaryPattern.FindAllStringIndex(extract.String(), -1)
if len(matches) > 0 {
extract = extract[:matches[len(matches)-1][1]]
match := matches[len(matches)-1]
if len(match) > 1 {
until := match[1]
if until < len(extract) {
extract = extract[:until]
}
}
}
}
msg.buffer = append(msg.buffer, extract)

View File

@ -210,7 +210,7 @@ func (list *RoomList) Clear() {
func (list *RoomList) SetSelected(tag string, room *rooms.Room) {
list.selected = room
list.selectedTag = ""
list.selectedTag = tag
}
func (list *RoomList) HasSelected() bool {
@ -264,7 +264,9 @@ func (list *RoomList) Previous() (string, *rooms.Room) {
items := list.items[list.selectedTag]
index := list.indexInTag(list.selectedTag, list.selected)
if index == len(items)-1 {
if index == -1 {
return list.First()
} else if index == len(items)-1 {
tagIndex := list.IndexTag(list.selectedTag)
tagIndex++
for ; tagIndex < len(list.tags); tagIndex++ {
@ -288,7 +290,9 @@ func (list *RoomList) Next() (string, *rooms.Room) {
items := list.items[list.selectedTag]
index := list.indexInTag(list.selectedTag, list.selected)
if index == 0 {
if index == -1 {
return list.Last()
} else if index == 0 {
tagIndex := list.IndexTag(list.selectedTag)
tagIndex--
for ; tagIndex >= 0; tagIndex-- {
@ -332,6 +336,8 @@ func (list *RoomList) Get(n int) (string, *rooms.Room) {
// Tag items
n -= len(items)
// Tag footer
n--
}
return "", nil
}
@ -420,5 +426,6 @@ func (list *RoomList) Draw(screen tcell.Screen) {
break
}
}
y++
}
}

View File

@ -336,12 +336,11 @@ func (view *MainView) RemoveRoom(roomID string) {
view.parent.Render()
}
func (view *MainView) SetRooms(roomIDs []string) {
func (view *MainView) SetRooms(rooms map[string]*rooms.Room) {
view.roomList.Clear()
view.roomView.Clear()
view.rooms = make(map[string]*RoomView)
for _, roomID := range roomIDs {
room := view.matrix.GetRoom(roomID)
for _, room := range rooms {
view.roomList.Add(room)
view.addRoomPage(room)
}