Skip to content

Commit 8e8f2da

Browse files
committed
allow paging when selecting messages
1 parent e8d9f26 commit 8e8f2da

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

main.go

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"gitlab.com/tslocum/cbind"
1818
)
1919

20-
var VERSION string = "v1.0.2"
20+
var VERSION string = "v1.0.3"
2121

2222
var sndTxt string = ""
2323
var currentReceiver messages.Chat = messages.Chat{}
@@ -248,38 +248,27 @@ func handleMessageCommand(command string) func(ev *tcell.EventKey) *tcell.EventK
248248
}
249249
}
250250

251-
func handleMessagesUp(ev *tcell.EventKey) *tcell.EventKey {
252-
if curRegions == nil || len(curRegions) == 0 {
253-
return nil
254-
}
255-
hls := textView.GetHighlights()
256-
if len(hls) > 0 {
257-
newId := GetOffsetMsgId(hls[0], -1)
258-
if newId != "" {
259-
textView.Highlight(newId)
251+
func handleMessagesMove(amount int) func(ev *tcell.EventKey) *tcell.EventKey {
252+
return func(ev *tcell.EventKey) *tcell.EventKey {
253+
if curRegions == nil || len(curRegions) == 0 {
254+
return nil
260255
}
261-
} else {
262-
textView.Highlight(curRegions[len(curRegions)-1].Id)
263-
}
264-
textView.ScrollToHighlight()
265-
return nil
266-
}
267-
268-
func handleMessagesDown(ev *tcell.EventKey) *tcell.EventKey {
269-
if curRegions == nil || len(curRegions) == 0 {
270-
return nil
271-
}
272-
hls := textView.GetHighlights()
273-
if len(hls) > 0 {
274-
newId := GetOffsetMsgId(hls[0], 1)
275-
if newId != "" {
276-
textView.Highlight(newId)
256+
hls := textView.GetHighlights()
257+
if len(hls) > 0 {
258+
newId := GetOffsetMsgId(hls[0], amount)
259+
if newId != "" {
260+
textView.Highlight(newId)
261+
}
262+
} else {
263+
if amount < 0 {
264+
textView.Highlight(curRegions[0].Id)
265+
} else {
266+
textView.Highlight(curRegions[len(curRegions)-1].Id)
267+
}
277268
}
278-
} else {
279-
textView.Highlight(curRegions[0].Id)
269+
textView.ScrollToHighlight()
270+
return nil
280271
}
281-
textView.ScrollToHighlight()
282-
return nil
283272
}
284273

285274
func handleChatPanelUp(ev *tcell.EventKey) *tcell.EventKey {
@@ -356,7 +345,7 @@ func LoadShortcuts() {
356345
PrintErrorMsg("command_help:", err)
357346
}
358347
app.SetInputCapture(keyBindings.Capture)
359-
// bindings for text input
348+
// bindings for chat message text view
360349
keysMessages := cbind.NewConfiguration()
361350
if err := keysMessages.Set(config.Config.Keymap.MessageDownload, handleMessageCommand("download")); err != nil {
362351
PrintErrorMsg("message_download:", err)
@@ -383,12 +372,16 @@ func LoadShortcuts() {
383372
PrintErrorMsg("message_revoke:", err)
384373
}
385374
keysMessages.SetKey(tcell.ModNone, tcell.KeyEscape, handleExitMessages)
386-
keysMessages.SetKey(tcell.ModNone, tcell.KeyUp, handleMessagesUp)
387-
keysMessages.SetKey(tcell.ModNone, tcell.KeyDown, handleMessagesDown)
388-
keysMessages.SetRune(tcell.ModNone, 'k', handleMessagesUp)
389-
keysMessages.SetRune(tcell.ModNone, 'j', handleMessagesDown)
375+
keysMessages.SetKey(tcell.ModNone, tcell.KeyUp, handleMessagesMove(-1))
376+
keysMessages.SetKey(tcell.ModNone, tcell.KeyDown, handleMessagesMove(1))
377+
keysMessages.SetKey(tcell.ModNone, tcell.KeyPgUp, handleMessagesMove(-10))
378+
keysMessages.SetKey(tcell.ModNone, tcell.KeyPgDn, handleMessagesMove(10))
379+
keysMessages.SetRune(tcell.ModNone, 'k', handleMessagesMove(-1))
380+
keysMessages.SetRune(tcell.ModNone, 'j', handleMessagesMove(1))
390381
keysMessages.SetRune(tcell.ModNone, 'g', handleMessagesFirst)
391382
keysMessages.SetRune(tcell.ModNone, 'G', handleMessagesLast)
383+
keysMessages.SetRune(tcell.ModCtrl, 'u', handleMessagesMove(-10))
384+
keysMessages.SetRune(tcell.ModCtrl, 'd', handleMessagesMove(10))
392385
textView.SetInputCapture(keysMessages.Capture)
393386
keysChatPanel := cbind.NewConfiguration()
394387
keysChatPanel.SetRune(tcell.ModCtrl, 'u', handleChatPanelUp)

0 commit comments

Comments
 (0)