-
Notifications
You must be signed in to change notification settings - Fork 135
Add new feature: Vim mode #368
base: master
Are you sure you want to change the base?
Changes from 12 commits
10de420
f0515f4
a15d76c
26d6a15
714e23b
ce00566
56fcff0
2016462
2c86b71
7219309
155c160
ad82e0e
9e0b15d
1b1c0c1
86df4fd
a2cc7de
5050954
422d825
87a8946
b55c343
b38cbd9
6de4e41
eea5b6b
1cc4e20
9e8bd4c
b2bd175
9d79a7f
076d73b
8774ec7
1e22b40
e7e4512
dfdc8c6
30b8b96
68d0832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ require ( | |
github.com/Bios-Marcel/shortnotforlong v1.1.1 | ||
github.com/alecthomas/chroma v0.7.3 | ||
github.com/atotto/clipboard v0.1.2 | ||
github.com/bunyk/gokeybr v0.0.0-20201019133936-f9e4ed3fdc5d // indirect | ||
github.com/gdamore/tcell/v2 v2.0.0 | ||
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28 | ||
github.com/google/go-github/v29 v29.0.3 | ||
|
@@ -20,6 +21,8 @@ require ( | |
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac | ||
github.com/sergi/go-diff v1.1.0 | ||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 | ||
golang.org/x/tools v0.0.0-20201112171726-b38955972a18 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous |
||
golang.org/x/tools/gopls v0.5.2 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous |
||
gopkg.in/sourcemap.v1 v1.0.5 // indirect | ||
rsc.io/qr v0.2.0 | ||
) |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/Bios-Marcel/cordless/util/files" | ||
"github.com/Bios-Marcel/cordless/util/fuzzy" | ||
"github.com/Bios-Marcel/cordless/util/text" | ||
"github.com/Bios-Marcel/cordless/util/vim" | ||
"github.com/Bios-Marcel/cordless/version" | ||
|
||
"github.com/Bios-Marcel/discordemojimap" | ||
|
@@ -42,6 +43,7 @@ import ( | |
"github.com/Bios-Marcel/cordless/ui/shortcutdialog" | ||
"github.com/Bios-Marcel/cordless/ui/tviewutil" | ||
"github.com/Bios-Marcel/cordless/util/maths" | ||
//"github.com/Bios-Marcel/cordless/util/vim" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's with this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot _:( |
||
) | ||
|
||
var ( | ||
|
@@ -91,6 +93,8 @@ type Window struct { | |
|
||
bareChat bool | ||
activeView ActiveView | ||
|
||
vimStatus *components.BottomBarItem | ||
} | ||
|
||
type ActiveView bool | ||
|
@@ -742,7 +746,13 @@ func NewWindow(app *tview.Application, session *discordgo.Session, readyEvent *d | |
|
||
window.userList = NewUserTree(window.session.State) | ||
|
||
if config.Current.OnTypeInListBehaviour == config.SearchOnTypeInList { | ||
// Disable search on type when in Vim mode. TODO add / shourtcut to search. | ||
if config.Current.VimMode.CurrentMode != vim.Disabled { | ||
guildList.SetSearchOnTypeEnabled(false) | ||
channelTree.SetSearchOnTypeEnabled(false) | ||
window.userList.internalTreeView.SetSearchOnTypeEnabled(false) | ||
window.privateList.internalTreeView.SetSearchOnTypeEnabled(false) | ||
} else if config.Current.OnTypeInListBehaviour == config.SearchOnTypeInList { | ||
guildList.SetSearchOnTypeEnabled(true) | ||
channelTree.SetSearchOnTypeEnabled(true) | ||
window.userList.internalTreeView.SetSearchOnTypeEnabled(true) | ||
|
@@ -758,6 +768,17 @@ func NewWindow(app *tview.Application, session *discordgo.Session, readyEvent *d | |
} | ||
|
||
newGuildHandler := func(event *tcell.EventKey) *tcell.EventKey { | ||
|
||
// Workaround for vim bindings inside list | ||
if shortcuts.VimSimKeyDown.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyDown, rune(tcell.KeyDown), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyUp.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyRight.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyRight, rune(tcell.KeyRight), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyLeft.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone) | ||
} | ||
if shortcuts.GuildListMarkRead.Equals(event) { | ||
selectedGuildNode := guildList.GetCurrentNode() | ||
if selectedGuildNode != nil && !readstate.HasGuildBeenRead(selectedGuildNode.GetReference().(string)) { | ||
|
@@ -787,6 +808,17 @@ func NewWindow(app *tview.Application, session *discordgo.Session, readyEvent *d | |
} | ||
|
||
newChannelListHandler := func(event *tcell.EventKey) *tcell.EventKey { | ||
|
||
// Workaround for vim bindings inside list | ||
if shortcuts.VimSimKeyDown.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyDown, rune(tcell.KeyDown), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyUp.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyRight.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyRight, rune(tcell.KeyRight), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyLeft.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone) | ||
} | ||
if shortcuts.ChannelTreeMarkRead.Equals(event) { | ||
selectedChannelNode := channelTree.GetCurrentNode() | ||
if selectedChannelNode != nil { | ||
|
@@ -862,6 +894,10 @@ func NewWindow(app *tview.Application, session *discordgo.Session, readyEvent *d | |
bottomBar := components.NewBottomBar() | ||
bottomBar.AddItem(fmt.Sprintf("Logged in as: '%s'", tviewutil.Escape(session.State.User.Username))) | ||
bottomBar.AddItem(fmt.Sprintf("View / Change shortcuts: %s", shortcutdialog.EventToString(shortcutsDialogShortcut))) | ||
// bottomBar.AddItem(fmt.Sprintf("Vim: %s", config.Current.VimMode.EnabledString())) | ||
window.vimStatus = bottomBar.AddDynamicItem() | ||
// Default content | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment provides no value. |
||
window.vimStatus.Content = fmt.Sprintf("Vim: %s", config.Current.VimMode.CurrentModeString()) | ||
window.rootContainer.AddItem(bottomBar, 1, 0, false) | ||
} | ||
|
||
|
@@ -955,8 +991,16 @@ important changes of the last two versions officially released. | |
|
||
[::b]THIS VERSION | ||
- Features | ||
- Changes | ||
- Bugfixes | ||
[::b]2020-11-16 | ||
- Features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be one item named Also, the |
||
- Added Vim mode | ||
- Enable vim mode in your config file, setting VimMode to 0. | ||
- Navigate menus with h j k l in normal mode, enter focus with either | ||
- insert mode or visual mode. | ||
- Navigate inside lists with vim keys. | ||
- Use some of your known bindings inside chat view, or selection mode. | ||
- More vim features will be added in next updates, and bugs will try to be | ||
- fixed :) | ||
[::b]2020-10-24 | ||
- Features | ||
- DM people via "p" in the chatview or use the dm-open command | ||
|
@@ -2114,8 +2158,23 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK | |
//window#Shutdown unnecessary, as we shut the whole process down. | ||
window.app.Stop() | ||
return nil | ||
} else if shortcuts.VimInsertMode.Equals(event) { | ||
config.Current.VimMode.Insert() | ||
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString()) | ||
return nil | ||
} else if shortcuts.VimVisualMode.Equals(event) { | ||
config.Current.VimMode.Visual() | ||
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString()) | ||
return nil | ||
} else if shortcuts.VimNormalMode.Equals(event) { | ||
config.Current.VimMode.Normal() | ||
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString()) | ||
return nil | ||
} | ||
|
||
window.app.QueueUpdateDraw(func() { | ||
}) | ||
|
||
// Maybe compare directly to table? | ||
if config.Current.DesktopNotificationsUserInactivityThreshold > 0 { | ||
window.userActive = true | ||
|
@@ -2133,6 +2192,17 @@ func (window *Window) handleChatWindowShortcuts(event *tcell.EventKey) *tcell.Ev | |
return event | ||
} | ||
|
||
// Workaround for vim bindings inside list | ||
if shortcuts.VimSimKeyDown.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyDown, rune(tcell.KeyDown), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyUp.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyRight.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyRight, rune(tcell.KeyRight), tcell.ModNone) | ||
} else if shortcuts.VimSimKeyLeft.Equals(event) { | ||
return tcell.NewEventKey(tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone) | ||
} | ||
|
||
if shortcuts.DirectionalFocusHandling(event, window.app) == nil { | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installed some things while working on this, thought I had reverted go.sum and go.mod. Will fix