focus shifting shortcuts are now configurable
MODIFY
shortcuts/shortcuts.go
shortcuts/shortcuts.go
@@ -98,6 +98,15 @@ var (
ExitApplication = addShortcut("exit_application", "Exit application",
globalScope, tcell.NewEventKey(tcell.KeyCtrlC, rune(tcell.KeyCtrlC), tcell.ModCtrl))
+ FocusUp = addShortcut("focus_up", "Focus the next widget above",
+ globalScope, tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModAlt))
+ FocusDown = addShortcut("focus_down", "Focus the next widget below",
+ globalScope, tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModAlt))
+ FocusLeft = addShortcut("focus_left", "Focus the next widget to the left",
+ globalScope, tcell.NewEventKey(tcell.KeyLeft, 0, tcell.ModAlt))
+ FocusRight = addShortcut("focus_right", "Focus the next widget to the right",
+ globalScope, tcell.NewEventKey(tcell.KeyRight, 0, tcell.ModAlt))
+
FocusChannelContainer = addShortcut("focus_channel_container", "Focus channel container",
globalScope, tcell.NewEventKey(tcell.KeyRune, 'c', tcell.ModAlt))
FocusUserContainer = addShortcut("focus_user_container", "Focus user container",

MODIFY
ui/window.go
ui/window.go
@@ -646,13 +646,12 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
captureFunc := func(event *tcell.EventKey) *tcell.EventKey {
messageToSend := window.messageInput.GetText()
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyUp {
+ if shortcuts.FocusUp.Equals(event) {
window.app.SetFocus(window.chatView.internalTextView)
return nil
}
- if event.Key() == tcell.KeyDown {
+ if shortcuts.FocusDown.Equals(event) {
if window.commandMode {
window.app.SetFocus(window.commandView.commandOutput)
} else {
@@ -661,7 +660,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
@@ -676,7 +675,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
if window.activeView == Guilds {
window.app.SetFocus(window.channelTree)
return nil
@@ -685,7 +684,6 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
}
- }
if event.Modifiers() == tcell.ModCtrl {
if event.Key() == tcell.KeyUp {
@@ -839,13 +837,12 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
//Guild Container arrow key navigation. Please end my life.
oldGuildListHandler := guildList.GetInputCapture()
newGuildHandler := func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyDown || event.Key() == tcell.KeyUp {
+ if shortcuts.FocusUp.Equals(event) || shortcuts.FocusDown.Equals(event) {
window.app.SetFocus(window.channelTree)
return nil
}
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
@@ -854,11 +851,10 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
window.app.SetFocus(window.chatView.internalTextView)
return nil
}
- }
return event
}
@@ -879,13 +875,13 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
//Channel Container arrow key navigation. Please end my life.
oldChannelListHandler := channelTree.GetInputCapture()
newChannelListHandler := func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyDown || event.Key() == tcell.KeyUp {
+
+ if shortcuts.FocusUp.Equals(event) || shortcuts.FocusDown.Equals(event) {
window.app.SetFocus(window.guildList)
return nil
}
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
@@ -898,7 +894,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
if window.commandMode {
window.app.SetFocus(window.commandView.commandOutput)
} else {
@@ -906,7 +902,6 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
return nil
}
- }
return event
}
@@ -927,13 +922,12 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
//Chatview arrow key navigation. Please end my life.
oldChatViewHandler := window.chatView.internalTextView.GetInputCapture()
newChatViewHandler := func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyDown {
+ if shortcuts.FocusDown.Equals(event) {
window.app.SetFocus(window.messageInput.GetPrimitive())
return nil
}
- if event.Key() == tcell.KeyUp {
+ if shortcuts.FocusUp.Equals(event) {
if window.commandMode {
window.app.SetFocus(window.commandView.commandInput.internalTextView)
} else {
@@ -942,7 +936,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
if window.activeView == Guilds {
window.app.SetFocus(window.guildList)
return nil
@@ -952,7 +946,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
}
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
@@ -966,7 +960,6 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
return nil
}
- }
return event
}
@@ -987,8 +980,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
//User Container arrow key navigation. Please end my life.
oldUserListHandler := window.userList.internalTreeView.GetInputCapture()
newUserListHandler := func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
if window.activeView == Guilds {
window.app.SetFocus(window.guildList)
return nil
@@ -998,11 +990,10 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
return nil
}
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
window.app.SetFocus(window.chatView.GetPrimitive())
return nil
}
- }
return event
}
@@ -1023,8 +1014,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
//Private Container arrow key navigation. Please end my life.
oldPrivateListHandler := window.privateList.internalTreeView.GetInputCapture()
newPrivateListHandler := func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyLeft {
+ if shortcuts.FocusLeft.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
@@ -1033,11 +1023,10 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}
- if event.Key() == tcell.KeyRight {
+ if shortcuts.FocusRight.Equals(event) {
window.app.SetFocus(window.chatView.internalTextView)
return nil
}
- }
return event
}
@@ -1078,48 +1067,36 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
})
window.commandView.SetInputCaptureForInput(func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyUp {
+ if shortcuts.FocusUp.Equals(event) {
window.app.SetFocus(window.commandView.commandOutput)
- } else if event.Key() == tcell.KeyDown {
+ } else if shortcuts.FocusDown.Equals(event) {
window.app.SetFocus(window.chatView.GetPrimitive())
- } else if event.Key() == tcell.KeyRight {
+ } else if shortcuts.FocusRight.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
window.app.SetFocus(window.channelTree)
}
- } else if event.Key() == tcell.KeyLeft {
+ } else if shortcuts.FocusLeft.Equals(event) {
window.app.SetFocus(window.channelTree)
- } else {
- return event
- }
-
- return nil
}
return event
})
window.commandView.SetInputCaptureForOutput(func(event *tcell.EventKey) *tcell.EventKey {
- if event.Modifiers() == tcell.ModAlt {
- if event.Key() == tcell.KeyUp {
+ if shortcuts.FocusUp.Equals(event) {
window.app.SetFocus(window.messageInput.GetPrimitive())
- } else if event.Key() == tcell.KeyDown {
+ } else if shortcuts.FocusDown.Equals(event) {
window.app.SetFocus(window.commandView.commandInput.GetPrimitive())
- } else if event.Key() == tcell.KeyRight {
+ } else if shortcuts.FocusRight.Equals(event) {
if window.userList.internalTreeView.IsVisible() {
window.app.SetFocus(window.userList.internalTreeView)
} else {
window.app.SetFocus(window.channelTree)
}
- } else if event.Key() == tcell.KeyLeft {
+ } else if shortcuts.FocusLeft.Equals(event) {
window.app.SetFocus(window.channelTree)
- } else {
- return event
- }
-
- return nil
}
return event

focus shifting shortcuts are now configurable