1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-19 21:28:28 +02:00

support alt-enter for inserting newline when typing commit message within the app

This commit is contained in:
Jesse Duffield 2021-04-02 15:08:15 +11:00
parent 28551c6654
commit 775789a13b
9 changed files with 27 additions and 17 deletions

2
go.mod

@ -20,7 +20,7 @@ require (
github.com/imdario/mergo v0.3.11 github.com/imdario/mergo v0.3.11
github.com/integrii/flaggy v1.4.0 github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001 github.com/jesseduffield/gocui v0.3.1-0.20210402040718-77a1b9631715
github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe // indirect github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe // indirect
github.com/jesseduffield/yaml v2.1.0+incompatible github.com/jesseduffield/yaml v2.1.0+incompatible
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0

2
go.sum

@ -92,6 +92,8 @@ github.com/jesseduffield/gocui v0.3.1-0.20210329131148-bcc4dcd991ff h1:fTt3EzLtp
github.com/jesseduffield/gocui v0.3.1-0.20210329131148-bcc4dcd991ff/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg= github.com/jesseduffield/gocui v0.3.1-0.20210329131148-bcc4dcd991ff/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001 h1:1WH+lTSK5YMr8emISHPA+VqYDDcLei6djuSxBCLIaiI= github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001 h1:1WH+lTSK5YMr8emISHPA+VqYDDcLei6djuSxBCLIaiI=
github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg= github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/gocui v0.3.1-0.20210402040718-77a1b9631715 h1:nELTdFJiZk3vv7j8nWoHvl7H2IqTr26EHKl6LaorRA8=
github.com/jesseduffield/gocui v0.3.1-0.20210402040718-77a1b9631715/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe h1:qsVhCf2RFyyKIUe/+gJblbCpXMUki9rZrHuEctg6M/E= github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe h1:qsVhCf2RFyyKIUe/+gJblbCpXMUki9rZrHuEctg6M/E=
github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4= github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4=
github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE= github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE=

@ -381,7 +381,7 @@ func GetDefaultConfig() *UserConfig {
DiffingMenuAlt: "<c-e>", DiffingMenuAlt: "<c-e>",
CopyToClipboard: "<c-o>", CopyToClipboard: "<c-o>",
SubmitEditorText: "<enter>", SubmitEditorText: "<enter>",
AppendNewline: "<tab>", AppendNewline: "<a-enter>",
}, },
Status: KeybindingStatusConfig{ Status: KeybindingStatusConfig{
CheckForUpdate: "u", CheckForUpdate: "u",

@ -11,7 +11,7 @@ import (
func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { func (gui *Gui) commitMessageEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool {
newlineKey, ok := gui.getKey(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline).(gocui.Key) newlineKey, ok := gui.getKey(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline).(gocui.Key)
if !ok { if !ok {
newlineKey = gocui.KeyTab newlineKey = gocui.KeyAltEnter
} }
matched := true matched := true

@ -53,8 +53,9 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyArrowDown: "▼", gocui.KeyArrowDown: "▼",
gocui.KeyArrowLeft: "◄", gocui.KeyArrowLeft: "◄",
gocui.KeyArrowRight: "►", gocui.KeyArrowRight: "►",
gocui.KeyTab: "tab", // ctrl+i gocui.KeyTab: "tab", // ctrl+i
gocui.KeyEnter: "enter", // ctrl+m gocui.KeyEnter: "enter", // ctrl+m
gocui.KeyAltEnter: "alt+enter",
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3 gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
gocui.KeyBackspace: "backspace", // ctrl+h gocui.KeyBackspace: "backspace", // ctrl+h
gocui.KeyCtrlSpace: "ctrl+space", // ctrl+~, ctrl+2 gocui.KeyCtrlSpace: "ctrl+space", // ctrl+~, ctrl+2
@ -133,6 +134,7 @@ var keymap = map[string]interface{}{
"<backspace>": gocui.KeyBackspace, "<backspace>": gocui.KeyBackspace,
"<tab>": gocui.KeyTab, "<tab>": gocui.KeyTab,
"<enter>": gocui.KeyEnter, "<enter>": gocui.KeyEnter,
"<a-enter>": gocui.KeyAltEnter,
"<esc>": gocui.KeyEsc, "<esc>": gocui.KeyEsc,
"<space>": gocui.KeySpace, "<space>": gocui.KeySpace,
"<f1>": gocui.KeyF1, "<f1>": gocui.KeyF1,

@ -5,6 +5,8 @@
package gocui package gocui
import ( import (
"unicode"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
@ -53,12 +55,8 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.MoveCursor(-1, 0, false) v.MoveCursor(-1, 0, false)
case key == KeyArrowRight: case key == KeyArrowRight:
v.MoveCursor(1, 0, false) v.MoveCursor(1, 0, false)
case key == KeyTab: case key == KeyEnter:
v.EditNewLine() v.EditNewLine()
case key == KeySpace:
v.EditWrite(' ')
case key == KeyInsert:
v.Overwrite = !v.Overwrite
case key == KeyCtrlU: case key == KeyCtrlU:
v.EditDeleteToStartOfLine() v.EditDeleteToStartOfLine()
case key == KeyCtrlA: case key == KeyCtrlA:
@ -66,12 +64,12 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
case key == KeyCtrlE: case key == KeyCtrlE:
v.EditGotoToEndOfLine() v.EditGotoToEndOfLine()
matched = true matched = true
// TODO: see if we need all three of these conditions: maybe the final one is sufficient
case ch != 0 && mod == 0 && unicode.IsPrint(ch):
v.EditWrite(ch)
default: default:
if ch != 0 && mod == 0 { matched = false
v.EditWrite(ch)
} else {
matched = false
}
} }
return matched return matched

@ -297,7 +297,8 @@ const (
// In tcell, these are not keys per se. But in gocui we have them // In tcell, these are not keys per se. But in gocui we have them
// mapped to the keys so we have to use placeholder keys. // mapped to the keys so we have to use placeholder keys.
MouseLeft = Key(tcell.KeyF63) // arbitrary assignments KeyAltEnter = Key(tcell.KeyF64) // arbitrary assignments
MouseLeft = Key(tcell.KeyF63)
MouseRight = Key(tcell.KeyF62) MouseRight = Key(tcell.KeyF62)
MouseMiddle = Key(tcell.KeyF61) MouseMiddle = Key(tcell.KeyF61)
MouseRelease = Key(tcell.KeyF60) MouseRelease = Key(tcell.KeyF60)

@ -151,7 +151,14 @@ func pollEvent() GocuiEvent {
// - shift - will be translated to the final code of rune // - shift - will be translated to the final code of rune
// - ctrl - is translated in the key // - ctrl - is translated in the key
mod = 0 mod = 0
} else if mod == tcell.ModAlt && k == tcell.KeyEnter {
// for the sake of convenience I'm having a KeyAltEnter key. I will likely
// regret this laziness in the future. We're arbitrarily mapping that to tcell's
// KeyF64.
mod = 0
k = tcell.KeyF64
} }
return GocuiEvent{ return GocuiEvent{
Type: eventKey, Type: eventKey,
Key: Key(k), Key: Key(k),

2
vendor/modules.txt vendored

@ -149,7 +149,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem
github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/index
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
# github.com/jesseduffield/gocui v0.3.1-0.20210402033412-1238f910f001 # github.com/jesseduffield/gocui v0.3.1-0.20210402040718-77a1b9631715
## explicit ## explicit
github.com/jesseduffield/gocui github.com/jesseduffield/gocui
# github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe # github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe