refactor(chat): use tview.SetFocus command instead of (*tview.Application).SetFocus

This commit is contained in:
ayn2op 2026-04-06 12:17:57 -04:00
parent bd045c1ac2
commit 086798b639
4 changed files with 24 additions and 28 deletions

2
go.mod
View file

@ -11,7 +11,7 @@ require (
github.com/alecthomas/chroma/v2 v2.23.1
github.com/andybalholm/brotli v1.2.1
github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97
github.com/ayn2op/tview v0.0.0-20260406015348-02d490edcf9c
github.com/ayn2op/tview v0.0.0-20260406161906-ef25e456de82
github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb
github.com/diamondburned/arikawa/v3 v3.6.1-0.20260311205148-176ad9b9440f
github.com/diamondburned/ningen/v3 v3.0.1-0.20260306213430-5a08d3a709b4

4
go.sum
View file

@ -14,8 +14,8 @@ github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eT
github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97 h1:WujETUV+v0DEJyZgjeLzQvihWyL80c0Tg4qf0dDo+Io=
github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97/go.mod h1:3kFnpNCa3dF6WryzOMCDao7PfZ7DTCh+pievlfuwV80=
github.com/ayn2op/tview v0.0.0-20260406015348-02d490edcf9c h1:LAUkiouSdOjU5aFHnzODCKY6czWiYqetkeN+79D5I4g=
github.com/ayn2op/tview v0.0.0-20260406015348-02d490edcf9c/go.mod h1:xgkca32kuEswK7Kzkfk3Pk24WHcKPjqK4xGmDi9QqOY=
github.com/ayn2op/tview v0.0.0-20260406161906-ef25e456de82 h1:kAo7WULTx8bPp72LLKFSw7f3ujc0zHYjq52o+UR/fow=
github.com/ayn2op/tview v0.0.0-20260406161906-ef25e456de82/go.mod h1:xgkca32kuEswK7Kzkfk3Pk24WHcKPjqK4xGmDi9QqOY=
github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View file

@ -451,8 +451,7 @@ func (mi *messageInput) tabSuggest() tview.Cmd {
}
mi.mentionsList.rebuild()
mi.showMentionList()
return nil
return mi.showMentionsList()
}
type memberList []discord.Member
@ -517,7 +516,7 @@ func (mi *messageInput) searchMember(gID discord.GuildID, name string) tview.Cmd
}
}
func (mi *messageInput) showMentionList() {
func (mi *messageInput) showMentionsList() tview.Cmd {
borders := 0
if mi.cfg.Theme.Border.Enabled {
borders = 1
@ -545,7 +544,7 @@ func (mi *messageInput) showMentionList() {
l.SetRect(x, y, w, h)
mi.chat.ShowLayer(mentionsListLayerName).SendToFront(mentionsListLayerName)
mi.chat.app.SetFocus(mi)
return tview.SetFocus(mi)
}
func (mi *messageInput) addMentionMember(gID discord.GuildID, m *discord.Member) bool {

View file

@ -872,17 +872,13 @@ func (ml *messagesList) Update(msg tview.Msg) tview.Cmd {
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.YankURL.Keybind):
return ml.yankURL()
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.Open.Keybind):
ml.open()
return nil
return ml.open()
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.Reply.Keybind):
ml.reply(false)
return nil
return ml.reply(false)
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.ReplyMention.Keybind):
ml.reply(true)
return nil
return ml.reply(true)
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.Edit.Keybind):
ml.editSelectedMessage()
return nil
return ml.editSelectedMessage()
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.Delete.Keybind):
return ml.deleteSelectedMessage()
case keybind.Matches(msg, ml.cfg.Keybinds.MessagesList.DeleteConfirm.Keybind):
@ -1066,17 +1062,17 @@ func (ml *messagesList) yankURL() tview.Cmd {
}
}
func (ml *messagesList) open() {
func (ml *messagesList) open() tview.Cmd {
msg, err := ml.selectedMessage()
if err != nil {
slog.Error("failed to get selected message", "err", err)
return
return nil
}
urls := messageURLs(*msg)
if len(urls) == 0 && len(msg.Attachments) == 0 {
return
return nil
}
if len(urls)+len(msg.Attachments) == 1 {
@ -1091,8 +1087,9 @@ func (ml *messagesList) open() {
}
}
} else {
ml.showAttachmentsList(urls, msg.Attachments)
return ml.showAttachmentsList(urls, msg.Attachments)
}
return nil
}
func extractURLs(content string) []string {
@ -1154,7 +1151,7 @@ func messageURLs(msg discord.Message) []string {
return urls
}
func (ml *messagesList) showAttachmentsList(urls []string, attachments []discord.Attachment) {
func (ml *messagesList) showAttachmentsList(urls []string, attachments []discord.Attachment) tview.Cmd {
var items []attachmentItem
for _, a := range attachments {
attachment := a
@ -1188,7 +1185,7 @@ func (ml *messagesList) showAttachmentsList(urls []string, attachments []discord
layers.WithOverlay(),
).
SendToFront(attachmentsPickerLayerName)
ml.chatView.app.SetFocus(ml.attachmentsPicker)
return tview.SetFocus(ml.attachmentsPicker)
}
func (ml *messagesList) openAttachment(attachment discord.Attachment) {
@ -1230,11 +1227,11 @@ func (ml *messagesList) openURL(url string) {
}
}
func (ml *messagesList) reply(mention bool) {
func (ml *messagesList) reply(mention bool) tview.Cmd {
message, err := ml.selectedMessage()
if err != nil {
slog.Error("failed to get selected message", "err", err)
return
return nil
}
name := message.Author.DisplayOrUsername()
@ -1254,26 +1251,26 @@ func (ml *messagesList) reply(mention bool) {
ml.chatView.messageInput.sendMessageData = data
ml.chatView.messageInput.SetTitle(title + name)
ml.chatView.app.SetFocus(ml.chatView.messageInput)
return tview.SetFocus(ml.chatView.messageInput)
}
func (ml *messagesList) editSelectedMessage() {
func (ml *messagesList) editSelectedMessage() tview.Cmd {
message, err := ml.selectedMessage()
if err != nil {
slog.Error("failed to get selected message", "err", err)
return
return nil
}
me, _ := ml.chatView.state.Cabinet.Me()
if message.Author.ID != me.ID {
slog.Error("failed to edit message; not the author", "channel_id", message.ChannelID, "message_id", message.ID)
return
return nil
}
ml.chatView.messageInput.SetTitle("Editing")
ml.chatView.messageInput.edit = true
ml.chatView.messageInput.SetText(message.Content, true)
ml.chatView.app.SetFocus(ml.chatView.messageInput)
return tview.SetFocus(ml.chatView.messageInput)
}
func (ml *messagesList) confirmDelete() {