Skip to content

Commit

Permalink
Fixed bug in key event handling between vim modes, where the same key…
Browse files Browse the repository at this point in the history
… event could get interpreted repeatedly. Also some rewrites/improvements of the code. Key mappings can now contain control characters and meta keys with a vim-like notation. There's a hard insert mode, which disables all of browsh's shortcuts and requires 4 hits on ESC to leave. There's a new multiple link opening feature analogous to vimium, that's still incomplete.
  • Loading branch information
tobimensch authored and tombh committed Jun 24, 2019
1 parent 9359837 commit b2ade39
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 138 deletions.
102 changes: 58 additions & 44 deletions interfacer/src/browsh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,64 @@ func setDefaults() {
viper.SetDefault("tty.keys.next-tab", []string{"\u001c", "28", "2"})

// Vim commands
vimCommandsBindings["gg"] = "scrollToTop"
vimCommandsBindings["G"] = "scrollToBottom"
vimCommandsBindings["j"] = "scrollDown"
vimCommandsBindings["k"] = "scrollUp"
vimCommandsBindings["h"] = "scrollLeft"
vimCommandsBindings["l"] = "scrollRight"
vimCommandsBindings["d"] = "scrollHalfPageDown"
vimCommandsBindings["u"] = "scrollHalfPageUp"
vimCommandsBindings["e"] = "editURL"
vimCommandsBindings["ge"] = "editURL"
vimCommandsBindings["gE"] = "editURLInNewTab"
vimCommandsBindings["H"] = "historyBack"
vimCommandsBindings["L"] = "historyForward"
vimCommandsBindings["J"] = "prevTab"
vimCommandsBindings["K"] = "nextTab"
vimCommandsBindings["r"] = "reload"
vimCommandsBindings["xx"] = "removeTab"
vimCommandsBindings["X"] = "restoreTab"
vimCommandsBindings["t"] = "newTab"
vimCommandsBindings["/"] = "findMode"
vimCommandsBindings["n"] = "findNext"
vimCommandsBindings["N"] = "findPrevious"
vimCommandsBindings["g0"] = "firstTab"
vimCommandsBindings["g$"] = "lastTab"
vimCommandsBindings["gu"] = "urlUp"
vimCommandsBindings["gU"] = "urlRoot"
vimCommandsBindings["<<"] = "moveTabLeft"
vimCommandsBindings[">>"] = "moveTabRight"
vimCommandsBindings["^"] = "previouslyVisitedTab"
vimCommandsBindings["m"] = "makeMark"
vimCommandsBindings["'"] = "gotoMark"
vimCommandsBindings["i"] = "insertMode"
vimCommandsBindings["yy"] = "copyURL"
vimCommandsBindings["p"] = "openClipboardURL"
vimCommandsBindings["P"] = "openClipboardURLInNewTab"
vimCommandsBindings["gi"] = "focusFirstTextInput"
vimCommandsBindings["f"] = "openLinkInCurrentTab"
vimCommandsBindings["F"] = "openLinkInNewTab"
vimCommandsBindings["yf"] = "copyLinkURL"
vimCommandsBindings["[["] = "followLinkLabeledPrevious"
vimCommandsBindings["]]"] = "followLinkLabeledNext"
vimCommandsBindings["yt"] = "duplicateTab"
vimCommandsBindings["v"] = "visualMode"
vimCommandsBindings["?"] = "viewHelp"
vimKeyMap["normal gg"] = "scrollToTop"
vimKeyMap["normal G"] = "scrollToBottom"
vimKeyMap["normal j"] = "scrollDown"
vimKeyMap["normal k"] = "scrollUp"
vimKeyMap["normal h"] = "scrollLeft"
vimKeyMap["normal l"] = "scrollRight"
vimKeyMap["normal d"] = "scrollHalfPageDown"
vimKeyMap["normal <C-d>"] = "scrollHalfPageDown"
vimKeyMap["normal u"] = "scrollHalfPageUp"
vimKeyMap["normal <C-u>"] = "scrollHalfPageUp"
vimKeyMap["normal e"] = "editURL"
vimKeyMap["normal ge"] = "editURL"
vimKeyMap["normal gE"] = "editURLInNewTab"
vimKeyMap["normal H"] = "historyBack"
vimKeyMap["normal L"] = "historyForward"
vimKeyMap["normal J"] = "prevTab"
vimKeyMap["normal K"] = "nextTab"
vimKeyMap["normal r"] = "reload"
vimKeyMap["normal xx"] = "removeTab"
vimKeyMap["normal X"] = "restoreTab"
vimKeyMap["normal t"] = "newTab"
vimKeyMap["normal T"] = "searchForTab"
vimKeyMap["normal /"] = "findMode"
vimKeyMap["normal n"] = "findNext"
vimKeyMap["normal N"] = "findPrevious"
vimKeyMap["normal g0"] = "firstTab"
vimKeyMap["normal g$"] = "lastTab"
vimKeyMap["normal gu"] = "urlUp"
vimKeyMap["normal gU"] = "urlRoot"
vimKeyMap["normal <<"] = "moveTabLeft"
vimKeyMap["normal >>"] = "moveTabRight"
vimKeyMap["normal ^"] = "previouslyVisitedTab"
vimKeyMap["normal m"] = "makeMark"
vimKeyMap["normal '"] = "gotoMark"
vimKeyMap["normal i"] = "insertMode"
vimKeyMap["normal I"] = "insertModeHard"
vimKeyMap["normal yy"] = "copyURL"
vimKeyMap["normal p"] = "openClipboardURL"
vimKeyMap["normal P"] = "openClipboardURLInNewTab"
vimKeyMap["normal gi"] = "focusFirstTextInput"
vimKeyMap["normal f"] = "openLinkInCurrentTab"
vimKeyMap["normal F"] = "openLinkInNewTab"
vimKeyMap["normal <M-f>"] = "openMultipleLinksInNewTab"
vimKeyMap["normal yf"] = "copyLinkURL"
vimKeyMap["normal [["] = "followLinkLabeledPrevious"
vimKeyMap["normal ]]"] = "followLinkLabeledNext"
vimKeyMap["normal yt"] = "duplicateTab"
vimKeyMap["normal v"] = "visualMode"
vimKeyMap["normal ?"] = "viewHelp"
vimKeyMap["caret v"] = "visualMode"
vimKeyMap["caret h"] = "moveCaretLeft"
vimKeyMap["caret l"] = "moveCaretRight"
vimKeyMap["caret j"] = "moveCaretDown"
vimKeyMap["caret k"] = "moveCaretUp"
vimKeyMap["caret <Enter>"] = "clickAtCaretPosition"
vimKeyMap["visual c"] = "caretMode"
vimKeyMap["visual o"] = "swapVisualModeCursorPosition"
vimKeyMap["visual y"] = "copyVisualModeSelection"
}

func loadConfig() {
Expand Down
8 changes: 7 additions & 1 deletion interfacer/src/browsh/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func readStdin() {
}
}

func handleUserKeyPress(ev *tcell.EventKey) {
func handleShortcuts(ev *tcell.EventKey) {
if CurrentTab == nil {
if ev.Key() == tcell.KeyCtrlQ {
quitBrowsh()
Expand Down Expand Up @@ -88,6 +88,12 @@ func handleUserKeyPress(ev *tcell.EventKey) {
if isKey("tty.keys.next-tab", ev) {
nextTab()
}
}

func handleUserKeyPress(ev *tcell.EventKey) {
if currentVimMode != insertModeHard {
handleShortcuts(ev)
}
if !urlInputBox.isActive {
forwardKeyPress(ev)
}
Expand Down
10 changes: 7 additions & 3 deletions interfacer/src/browsh/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ func overlayVimMode() {
switch currentVimMode {
case insertMode:
writeString(0, height-1, "ins", tcell.StyleDefault)
case insertModeHard:
writeString(0, height-1, "INS", tcell.StyleDefault)
case linkMode:
writeString(0, height-1, "lnk", tcell.StyleDefault)
case linkModeNewTab:
writeString(0, height-1, "LNK", tcell.StyleDefault)
case linkModeMultipleNewTab:
writeString(0, height-1, "*LNK", tcell.StyleDefault)
case linkModeCopy:
writeString(0, height-1, "cp", tcell.StyleDefault)
case visualMode:
Expand All @@ -128,14 +132,14 @@ func overlayVimMode() {
writeString(caretPos.X, caretPos.Y, "#", tcell.StyleDefault)
case findMode:
writeString(0, height-1, "/"+findText, tcell.StyleDefault)
case makeMarkMode:
case markModeMake:
writeString(0, height-1, "mark", tcell.StyleDefault)
case gotoMarkMode:
case markModeGoto:
writeString(0, height-1, "goto", tcell.StyleDefault)
}

switch currentVimMode {
case linkMode, linkModeNewTab, linkModeCopy:
case linkMode, linkModeNewTab, linkModeMultipleNewTab, linkModeCopy:
if !linkModeWithHints {
findAndHighlightTextOnScreen(linkText)
}
Expand Down
Loading

0 comments on commit b2ade39

Please sign in to comment.