forked from Mirrors/gomuks
Restore ability to scroll inbox
This commit is contained in:
parent
a6d6f7af04
commit
2722459f22
1 changed files with 69 additions and 49 deletions
|
@ -61,8 +61,8 @@ type RosterView struct {
|
||||||
splits []*split
|
splits []*split
|
||||||
splitLookup map[string]*split
|
splitLookup map[string]*split
|
||||||
|
|
||||||
height, width int
|
height, width,
|
||||||
//scrollOffset int
|
splitOffset, roomOffset int
|
||||||
focused bool
|
focused bool
|
||||||
|
|
||||||
parent *MainView
|
parent *MainView
|
||||||
|
@ -205,7 +205,7 @@ func (rstr *RosterView) Remove(room *rooms.Room) {
|
||||||
rstr.Lock()
|
rstr.Lock()
|
||||||
defer rstr.Unlock()
|
defer rstr.Unlock()
|
||||||
|
|
||||||
splt, index := rstr.index(room)
|
splt, index := rstr.indexOfRoom(room)
|
||||||
if index < 0 || index > len(splt.rooms) {
|
if index < 0 || index > len(splt.rooms) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ func (rstr *RosterView) Bump(room *rooms.Room) {
|
||||||
rstr.Add(room)
|
rstr.Add(room)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) index(room *rooms.Room) (*split, int) {
|
func (rstr *RosterView) indexOfRoom(room *rooms.Room) (*split, int) {
|
||||||
if room == nil {
|
if room == nil {
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,15 @@ func (rstr *RosterView) index(room *rooms.Room) (*split, int) {
|
||||||
return nil, -1
|
return nil, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rstr *RosterView) indexOfSplit(split *split) int {
|
||||||
|
for index, entry := range rstr.splits {
|
||||||
|
if entry == split {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) getMostRecentMessage(room *rooms.Room) (string, bool) {
|
func (rstr *RosterView) getMostRecentMessage(room *rooms.Room) (string, bool) {
|
||||||
roomView, _ := rstr.parent.getRoomView(room.ID, true)
|
roomView, _ := rstr.parent.getRoomView(room.ID, true)
|
||||||
|
|
||||||
|
@ -285,18 +294,22 @@ func (rstr *RosterView) Last() (*split, *rooms.Room) {
|
||||||
return rstr.splits[len(rstr.splits)-1], rstr.splits[len(rstr.splits)-1].rooms[0]
|
return rstr.splits[len(rstr.splits)-1], rstr.splits[len(rstr.splits)-1].rooms[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) ScrollNext() {
|
func (rstr *RosterView) MatchOffsetsToSelection() {
|
||||||
rstr.Lock()
|
rstr.Lock()
|
||||||
defer rstr.Unlock()
|
defer rstr.Unlock()
|
||||||
|
|
||||||
if splt, index := rstr.index(rstr.room); splt == nil || index == -1 {
|
var splt *split
|
||||||
|
splt, rstr.roomOffset = rstr.indexOfRoom(rstr.room)
|
||||||
|
rstr.splitOffset = rstr.indexOfSplit(splt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rstr *RosterView) ScrollNext() {
|
||||||
|
rstr.Lock()
|
||||||
|
|
||||||
|
if splt, index := rstr.indexOfRoom(rstr.room); splt == nil || index == -1 {
|
||||||
rstr.split, rstr.room = rstr.first()
|
rstr.split, rstr.room = rstr.first()
|
||||||
//rstr.scrollOffset = 0
|
|
||||||
} else if index < len(splt.rooms)-1 && !splt.collapsed {
|
} else if index < len(splt.rooms)-1 && !splt.collapsed {
|
||||||
rstr.room = splt.rooms[index+1]
|
rstr.room = splt.rooms[index+1]
|
||||||
//if rstr.VisualScrollHeight(rstr.scrollOffset, index+2) >= rstr.height {
|
|
||||||
// rstr.scrollOffset++
|
|
||||||
//}
|
|
||||||
} else {
|
} else {
|
||||||
idx := -1
|
idx := -1
|
||||||
for i, s := range rstr.splits {
|
for i, s := range rstr.splits {
|
||||||
|
@ -308,32 +321,42 @@ func (rstr *RosterView) ScrollNext() {
|
||||||
if len(rstr.splits[i].rooms) > 0 {
|
if len(rstr.splits[i].rooms) > 0 {
|
||||||
rstr.split = rstr.splits[i]
|
rstr.split = rstr.splits[i]
|
||||||
rstr.room = rstr.splits[i].rooms[0]
|
rstr.room = rstr.splits[i].rooms[0]
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rstr.Unlock()
|
||||||
|
|
||||||
|
if rstr.HeightThroughSelection() > rstr.height {
|
||||||
|
rstr.MatchOffsetsToSelection()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) ScrollPrev() {
|
func (rstr *RosterView) ScrollPrev() {
|
||||||
rstr.Lock()
|
rstr.Lock()
|
||||||
defer rstr.Unlock()
|
defer rstr.Unlock()
|
||||||
|
|
||||||
if splt, index := rstr.index(rstr.room); splt == nil || index == -1 {
|
if splt, index := rstr.indexOfRoom(rstr.room); splt == nil || index == -1 {
|
||||||
return
|
return
|
||||||
} else if index > 0 && !splt.collapsed {
|
} else if index > 0 && !splt.collapsed {
|
||||||
rstr.room = splt.rooms[index-1]
|
rstr.room = splt.rooms[index-1]
|
||||||
//if index == rstr.scrollOffset {
|
if index == rstr.roomOffset {
|
||||||
// rstr.scrollOffset--
|
rstr.roomOffset--
|
||||||
//}
|
}
|
||||||
} else {
|
} else {
|
||||||
for idx := len(rstr.splits) - 1; idx > 0; idx-- {
|
for idx := len(rstr.splits) - 1; idx > 0; idx-- {
|
||||||
if rstr.splits[idx] == rstr.split {
|
if rstr.splits[idx] == rstr.split {
|
||||||
rstr.split = rstr.splits[idx-1]
|
rstr.split = rstr.splits[idx-1]
|
||||||
|
rstr.splitOffset = idx - 1
|
||||||
|
|
||||||
if len(rstr.split.rooms) > 0 {
|
if len(rstr.split.rooms) > 0 {
|
||||||
if rstr.split.collapsed {
|
if rstr.split.collapsed {
|
||||||
rstr.room = rstr.split.rooms[0]
|
rstr.room = rstr.split.rooms[0]
|
||||||
|
rstr.roomOffset = 0
|
||||||
} else {
|
} else {
|
||||||
rstr.room = rstr.split.rooms[len(rstr.split.rooms)-1]
|
rstr.room = rstr.split.rooms[len(rstr.split.rooms)-1]
|
||||||
|
rstr.roomOffset = len(rstr.split.rooms) - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -342,21 +365,28 @@ func (rstr *RosterView) ScrollPrev() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) VisualScrollHeight(start, end int) int {
|
func (rstr *RosterView) HeightThroughSelection() int {
|
||||||
if start < 0 || start > end {
|
height := 3
|
||||||
return -1
|
for _, splt := range rstr.splits[rstr.splitOffset:] {
|
||||||
|
if len(splt.rooms) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
height++
|
||||||
|
if splt.collapsed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range splt.rooms[rstr.roomOffset:] {
|
||||||
|
height += 2
|
||||||
|
if r == rstr.room {
|
||||||
|
return height
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 3 + (2 * (end - start))
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rstr *RosterView) RoomsOnScreen() int {
|
|
||||||
return (rstr.height - 3) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
//func (rstr *RosterView) IndexOfLastVisibleRoom() int {
|
|
||||||
// return rstr.scrollOffset + rstr.RoomsOnScreen()
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (rstr *RosterView) Draw(screen mauview.Screen) {
|
func (rstr *RosterView) Draw(screen mauview.Screen) {
|
||||||
if rstr.focused {
|
if rstr.focused {
|
||||||
if roomView, ok := rstr.parent.getRoomView(rstr.room.ID, true); ok {
|
if roomView, ok := rstr.parent.getRoomView(rstr.room.ID, true); ok {
|
||||||
|
@ -384,7 +414,7 @@ func (rstr *RosterView) Draw(screen mauview.Screen) {
|
||||||
widget.NewBorder().Draw(mauview.NewProxyScreen(screen, 2, 3, rstr.width-5, 1))
|
widget.NewBorder().Draw(mauview.NewProxyScreen(screen, 2, 3, rstr.width-5, 1))
|
||||||
|
|
||||||
y := 4
|
y := 4
|
||||||
for _, splt := range rstr.splits {
|
for _, splt := range rstr.splits[rstr.splitOffset:] {
|
||||||
|
|
||||||
if len(splt.rooms) == 0 {
|
if len(splt.rooms) == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -399,7 +429,12 @@ func (rstr *RosterView) Draw(screen mauview.Screen) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, room := range splt.rooms {
|
iter := splt.rooms
|
||||||
|
if splt == rstr.split {
|
||||||
|
iter = iter[rstr.roomOffset:]
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, room := range iter {
|
||||||
if room.IsReplaced() {
|
if room.IsReplaced() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -482,18 +517,16 @@ func (rstr *RosterView) OnKeyEvent(event mauview.KeyEvent) bool {
|
||||||
rstr.ScrollNext()
|
rstr.ScrollNext()
|
||||||
case "prev_room":
|
case "prev_room":
|
||||||
rstr.ScrollPrev()
|
rstr.ScrollPrev()
|
||||||
|
rstr.MatchOffsetsToSelection()
|
||||||
case "top":
|
case "top":
|
||||||
rstr.Lock()
|
rstr.Lock()
|
||||||
defer rstr.Unlock()
|
|
||||||
rstr.split, rstr.room = rstr.first()
|
rstr.split, rstr.room = rstr.first()
|
||||||
//rstr.scrollOffset = 0
|
rstr.Unlock()
|
||||||
|
rstr.MatchOffsetsToSelection()
|
||||||
case "bottom":
|
case "bottom":
|
||||||
rstr.split, rstr.room = rstr.Last()
|
rstr.split, rstr.room = rstr.Last()
|
||||||
|
if rstr.HeightThroughSelection() > rstr.height {
|
||||||
if i := len(rstr.splits) - rstr.RoomsOnScreen(); i < 0 {
|
rstr.MatchOffsetsToSelection()
|
||||||
//rstr.scrollOffset = 0
|
|
||||||
} else {
|
|
||||||
//rstr.scrollOffset = i
|
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
rstr.split = nil
|
rstr.split = nil
|
||||||
|
@ -532,19 +565,6 @@ func (rstr *RosterView) OnMouseEvent(event mauview.MouseEvent) bool {
|
||||||
case tcell.WheelDown:
|
case tcell.WheelDown:
|
||||||
rstr.ScrollNext()
|
rstr.ScrollNext()
|
||||||
return true
|
return true
|
||||||
//case tcell.Button1:
|
|
||||||
// _, y := event.Position()
|
|
||||||
// if y <= 3 || y > rstr.VisualScrollHeight(rstr.scrollOffset, rstr.IndexOfLastVisibleRoom()) {
|
|
||||||
// return false
|
|
||||||
// } else {
|
|
||||||
// index := rstr.scrollOffset + y/2 - 2
|
|
||||||
// if index > len(rstr.rooms)-1 {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// rstr.selected = rstr.rooms[index]
|
|
||||||
// rstr.focused = true
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Add table
Reference in a new issue