refactor(ui): move help keybinds to keymap.go
This commit is contained in:
parent
2e6fa88608
commit
688cb05f67
5 changed files with 130 additions and 119 deletions
62
internal/ui/chat/composer/keymap.go
Normal file
62
internal/ui/chat/composer/keymap.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package composer
|
||||
|
||||
import (
|
||||
"github.com/ayn2op/tview/help"
|
||||
"github.com/ayn2op/tview/keybind"
|
||||
)
|
||||
|
||||
var _ help.KeyMap = Model{}
|
||||
|
||||
func (m Model) ShortHelp() []keybind.Keybind {
|
||||
if m.mentionsListVisible() {
|
||||
cfg := m.cfg.Keybinds.MentionsList
|
||||
ccfg := m.cfg.Keybinds.Composer
|
||||
short := []keybind.Keybind{cfg.SelectUp.Keybind, cfg.SelectDown.Keybind, ccfg.TabComplete.Keybind, ccfg.Cancel.Keybind}
|
||||
if m.canAttachFiles() {
|
||||
short = append(short, ccfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
return short
|
||||
}
|
||||
|
||||
cfg := m.cfg.Keybinds.Composer
|
||||
short := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
|
||||
if m.canEditLastMessage() {
|
||||
short = append(short, cfg.EditLast.Keybind)
|
||||
}
|
||||
if m.sendMessageData.Reference != nil {
|
||||
short = append(short, cfg.ToggleReplyMention.Keybind)
|
||||
}
|
||||
if m.canAttachFiles() {
|
||||
short = append(short, cfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
return short
|
||||
}
|
||||
|
||||
func (m Model) FullHelp() [][]keybind.Keybind {
|
||||
if m.mentionsListVisible() {
|
||||
mcfg := m.cfg.Keybinds.MentionsList
|
||||
ccfg := m.cfg.Keybinds.Composer
|
||||
return [][]keybind.Keybind{
|
||||
{mcfg.SelectUp.Keybind, mcfg.SelectDown.Keybind, mcfg.SelectTop.Keybind, mcfg.SelectBottom.Keybind},
|
||||
{ccfg.TabComplete.Keybind, ccfg.Cancel.Keybind},
|
||||
}
|
||||
}
|
||||
|
||||
cfg := m.cfg.Keybinds.Composer
|
||||
openEditor := []keybind.Keybind{cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
|
||||
|
||||
if m.canAttachFiles() {
|
||||
openEditor = append(openEditor, cfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
|
||||
compose := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Undo.Keybind}
|
||||
compose = append(compose, cfg.EditLast.Keybind)
|
||||
if m.sendMessageData.Reference != nil {
|
||||
compose = append(compose, cfg.ToggleReplyMention.Keybind)
|
||||
}
|
||||
|
||||
return [][]keybind.Keybind{
|
||||
compose,
|
||||
openEditor,
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/ayn2op/ningen/v3"
|
||||
"github.com/ayn2op/tview"
|
||||
"github.com/ayn2op/tview/box"
|
||||
"github.com/ayn2op/tview/help"
|
||||
"github.com/ayn2op/tview/keybind"
|
||||
"github.com/ayn2op/tview/textarea"
|
||||
"github.com/gdamore/tcell/v3"
|
||||
|
|
@ -75,8 +74,6 @@ type Model struct {
|
|||
// TypingDuration is how long Discord shows someone as typing after they start.
|
||||
const TypingDuration = 10 * time.Second
|
||||
|
||||
var _ help.KeyMap = Model{}
|
||||
|
||||
func NewModel(cfg *config.Config, state *ningen.State) Model {
|
||||
c := Model{
|
||||
disabled: true,
|
||||
|
|
@ -629,60 +626,6 @@ func (m Model) editAction(key tview.KeyMsg) textarea.Action {
|
|||
return textarea.ActionNone
|
||||
}
|
||||
|
||||
func (m Model) ShortHelp() []keybind.Keybind {
|
||||
if m.mentionsListVisible() {
|
||||
cfg := m.cfg.Keybinds.MentionsList
|
||||
ccfg := m.cfg.Keybinds.Composer
|
||||
short := []keybind.Keybind{cfg.SelectUp.Keybind, cfg.SelectDown.Keybind, ccfg.TabComplete.Keybind, ccfg.Cancel.Keybind}
|
||||
if m.canAttachFiles() {
|
||||
short = append(short, ccfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
return short
|
||||
}
|
||||
|
||||
cfg := m.cfg.Keybinds.Composer
|
||||
short := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
|
||||
if m.canEditLastMessage() {
|
||||
short = append(short, cfg.EditLast.Keybind)
|
||||
}
|
||||
if m.sendMessageData.Reference != nil {
|
||||
short = append(short, cfg.ToggleReplyMention.Keybind)
|
||||
}
|
||||
if m.canAttachFiles() {
|
||||
short = append(short, cfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
return short
|
||||
}
|
||||
|
||||
func (m Model) FullHelp() [][]keybind.Keybind {
|
||||
if m.mentionsListVisible() {
|
||||
mcfg := m.cfg.Keybinds.MentionsList
|
||||
ccfg := m.cfg.Keybinds.Composer
|
||||
return [][]keybind.Keybind{
|
||||
{mcfg.SelectUp.Keybind, mcfg.SelectDown.Keybind, mcfg.SelectTop.Keybind, mcfg.SelectBottom.Keybind},
|
||||
{ccfg.TabComplete.Keybind, ccfg.Cancel.Keybind},
|
||||
}
|
||||
}
|
||||
|
||||
cfg := m.cfg.Keybinds.Composer
|
||||
openEditor := []keybind.Keybind{cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
|
||||
|
||||
if m.canAttachFiles() {
|
||||
openEditor = append(openEditor, cfg.OpenFilePicker.Keybind)
|
||||
}
|
||||
|
||||
compose := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Undo.Keybind}
|
||||
compose = append(compose, cfg.EditLast.Keybind)
|
||||
if m.sendMessageData.Reference != nil {
|
||||
compose = append(compose, cfg.ToggleReplyMention.Keybind)
|
||||
}
|
||||
|
||||
return [][]keybind.Keybind{
|
||||
compose,
|
||||
openEditor,
|
||||
}
|
||||
}
|
||||
|
||||
func humanJoin(items []string) string {
|
||||
count := len(items)
|
||||
switch count {
|
||||
|
|
|
|||
68
internal/ui/chat/messageslist/keymap.go
Normal file
68
internal/ui/chat/messageslist/keymap.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package messageslist
|
||||
|
||||
import (
|
||||
"github.com/ayn2op/discordo/internal/ui"
|
||||
"github.com/ayn2op/tview/help"
|
||||
"github.com/ayn2op/tview/keybind"
|
||||
)
|
||||
|
||||
var _ help.KeyMap = Model{}
|
||||
|
||||
func (m Model) ShortHelp() []keybind.Keybind {
|
||||
cfg := m.cfg.Keybinds.MessagesList
|
||||
help := []keybind.Keybind{
|
||||
cfg.SelectUp.Keybind,
|
||||
cfg.SelectDown.Keybind,
|
||||
cfg.Cancel.Keybind,
|
||||
}
|
||||
|
||||
if selectedMessage, ok := m.selectedMessage(); ok {
|
||||
if !ui.IsMe(m.state, selectedMessage.Author.ID) {
|
||||
help = append(help, cfg.Reply.Keybind)
|
||||
}
|
||||
if len(selectedMessage.Attachments) != 0 || len(messageURLs(*selectedMessage)) != 0 {
|
||||
help = append(help, cfg.Open.Keybind)
|
||||
}
|
||||
}
|
||||
|
||||
return help
|
||||
}
|
||||
|
||||
func (m Model) FullHelp() [][]keybind.Keybind {
|
||||
cfg := m.cfg.Keybinds.MessagesList
|
||||
var actions, manage, attachments []keybind.Keybind
|
||||
if message, ok := m.selectedMessage(); ok {
|
||||
mine := ui.IsMe(m.state, message.Author.ID)
|
||||
if !mine {
|
||||
actions = append(actions, cfg.Reply.Keybind, cfg.ReplyMention.Keybind)
|
||||
}
|
||||
if message.ReferencedMessage != nil {
|
||||
actions = append(actions, cfg.SelectReply.Keybind)
|
||||
}
|
||||
if mine {
|
||||
manage = append(manage, cfg.Edit.Keybind)
|
||||
}
|
||||
if m.canDeleteMessage(*message) {
|
||||
manage = append(manage, cfg.DeleteConfirm.Keybind)
|
||||
if len(cfg.Delete.Keys()) != 0 {
|
||||
manage = append(manage, cfg.Delete.Keybind)
|
||||
}
|
||||
}
|
||||
if len(message.Attachments) != 0 || len(messageURLs(*message)) != 0 {
|
||||
attachments = append(attachments, cfg.Open.Keybind, cfg.OpenInBrowser.Keybind)
|
||||
}
|
||||
if len(message.Attachments) != 0 {
|
||||
attachments = append(attachments, cfg.Download.Keybind)
|
||||
}
|
||||
}
|
||||
actions = append(actions, cfg.Cancel.Keybind)
|
||||
|
||||
return [][]keybind.Keybind{
|
||||
{cfg.SelectUp.Keybind, cfg.SelectDown.Keybind, cfg.SelectTop.Keybind, cfg.SelectBottom.Keybind},
|
||||
{cfg.ScrollUp.Keybind, cfg.ScrollDown.Keybind, cfg.ScrollTop.Keybind, cfg.ScrollBottom.Keybind},
|
||||
actions,
|
||||
manage,
|
||||
attachments,
|
||||
{cfg.YankContent.Keybind, cfg.YankURL.Keybind, cfg.YankID.Keybind},
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/ayn2op/discordo/internal/ui"
|
||||
"github.com/ayn2op/ningen/v3"
|
||||
"github.com/ayn2op/tview"
|
||||
"github.com/ayn2op/tview/help"
|
||||
tviewimage "github.com/ayn2op/tview/image"
|
||||
"github.com/ayn2op/tview/keybind"
|
||||
"github.com/ayn2op/tview/list"
|
||||
|
|
@ -67,8 +66,6 @@ type Model struct {
|
|||
cellWidth, cellHeight uint
|
||||
}
|
||||
|
||||
var _ help.KeyMap = Model{}
|
||||
|
||||
func NewModel(cfg *config.Config, state *ningen.State) Model {
|
||||
ml := Model{
|
||||
selectionState: list.NewSelectionState(),
|
||||
|
|
@ -1089,62 +1086,3 @@ func (m Model) InvalidateRendered() {
|
|||
m.items[i].view = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) ShortHelp() []keybind.Keybind {
|
||||
cfg := m.cfg.Keybinds.MessagesList
|
||||
help := []keybind.Keybind{
|
||||
cfg.SelectUp.Keybind,
|
||||
cfg.SelectDown.Keybind,
|
||||
cfg.Cancel.Keybind,
|
||||
}
|
||||
|
||||
if selectedMessage, ok := m.selectedMessage(); ok {
|
||||
if !ui.IsMe(m.state, selectedMessage.Author.ID) {
|
||||
help = append(help, cfg.Reply.Keybind)
|
||||
}
|
||||
if len(selectedMessage.Attachments) != 0 || len(messageURLs(*selectedMessage)) != 0 {
|
||||
help = append(help, cfg.Open.Keybind)
|
||||
}
|
||||
}
|
||||
|
||||
return help
|
||||
}
|
||||
|
||||
func (m Model) FullHelp() [][]keybind.Keybind {
|
||||
cfg := m.cfg.Keybinds.MessagesList
|
||||
var actions, manage, attachments []keybind.Keybind
|
||||
if message, ok := m.selectedMessage(); ok {
|
||||
mine := ui.IsMe(m.state, message.Author.ID)
|
||||
if !mine {
|
||||
actions = append(actions, cfg.Reply.Keybind, cfg.ReplyMention.Keybind)
|
||||
}
|
||||
if message.ReferencedMessage != nil {
|
||||
actions = append(actions, cfg.SelectReply.Keybind)
|
||||
}
|
||||
if mine {
|
||||
manage = append(manage, cfg.Edit.Keybind)
|
||||
}
|
||||
if m.canDeleteMessage(*message) {
|
||||
manage = append(manage, cfg.DeleteConfirm.Keybind)
|
||||
if len(cfg.Delete.Keys()) != 0 {
|
||||
manage = append(manage, cfg.Delete.Keybind)
|
||||
}
|
||||
}
|
||||
if len(message.Attachments) != 0 || len(messageURLs(*message)) != 0 {
|
||||
attachments = append(attachments, cfg.Open.Keybind, cfg.OpenInBrowser.Keybind)
|
||||
}
|
||||
if len(message.Attachments) != 0 {
|
||||
attachments = append(attachments, cfg.Download.Keybind)
|
||||
}
|
||||
}
|
||||
actions = append(actions, cfg.Cancel.Keybind)
|
||||
|
||||
return [][]keybind.Keybind{
|
||||
{cfg.SelectUp.Keybind, cfg.SelectDown.Keybind, cfg.SelectTop.Keybind, cfg.SelectBottom.Keybind},
|
||||
{cfg.ScrollUp.Keybind, cfg.ScrollDown.Keybind, cfg.ScrollTop.Keybind, cfg.ScrollBottom.Keybind},
|
||||
actions,
|
||||
manage,
|
||||
attachments,
|
||||
{cfg.YankContent.Keybind, cfg.YankURL.Keybind, cfg.YankID.Keybind},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue