Skip to content

Commit

Permalink
force cursor to be at end of line when opening confirmation panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 17, 2021
1 parent 9e5f031 commit b28b2d0
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 25 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/imdario/mergo v0.3.11
github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
github.com/jesseduffield/gocui v0.3.1-0.20210412130453-de7bb5079f9f
github.com/jesseduffield/gocui v0.3.1-0.20210417110745-37f79434200d
github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe // indirect
github.com/jesseduffield/yaml v2.1.0+incompatible
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
Expand All @@ -39,7 +39,7 @@ require (
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72 // indirect
golang.org/x/text v0.3.6 // indirect
)
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ github.com/jesseduffield/gocui v0.3.1-0.20210412113212-ee65bd542c08 h1:d003y2GBy
github.com/jesseduffield/gocui v0.3.1-0.20210412113212-ee65bd542c08/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/gocui v0.3.1-0.20210412130453-de7bb5079f9f h1:JPpHlvSrKNxro+K9rM3nEHCdZ16qD0hnEedHPF07OtA=
github.com/jesseduffield/gocui v0.3.1-0.20210412130453-de7bb5079f9f/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/gocui v0.3.1-0.20210417105214-bdf37de5c917 h1:H4THGOdAJf61wByuq8EHF/NAgtqrTxpSIPsrCXU9HAY=
github.com/jesseduffield/gocui v0.3.1-0.20210417105214-bdf37de5c917/go.mod h1:QWq79xplEoyhQO+dgpk3sojjTVRKjQklyTlzm5nC5Kg=
github.com/jesseduffield/gocui v0.3.1-0.20210417110745-37f79434200d h1:2BPcc19W0j576hvhxtKma4jcD/+qAYvw1ln2HcIEZGU=
github.com/jesseduffield/gocui v0.3.1-0.20210417110745-37f79434200d/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/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4=
github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE=
Expand Down Expand Up @@ -236,6 +240,8 @@ golang.org/x/sys v0.0.0-20210402192133-700132347e07 h1:4k6HsQjxj6hVMsI2Vf0yKlzt5
golang.org/x/sys v0.0.0-20210402192133-700132347e07/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6 h1:EC6+IGYTjPpRfv9a2b/6Puw0W+hLtAhkV1tPsXhutqs=
Expand Down
19 changes: 8 additions & 11 deletions pkg/gui/confirmation_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package gui

import (
"strings"
"time"

"github.com/fatih/color"
"github.com/jesseduffield/gocui"
Expand Down Expand Up @@ -216,19 +215,17 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error {
}
gui.Views.Confirmation.Editable = opts.editable
gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.defaultEditor)

if opts.editable {
go utils.Safe(func() {
// TODO: remove this wait (right now if you remove it the EditGotoToEndOfLine method doesn't seem to work)
time.Sleep(time.Millisecond)
gui.g.Update(func(g *gocui.Gui) error {
gui.Views.Confirmation.EditGotoToEndOfLine()
return nil
})
})
if err := gui.Views.Confirmation.SetEditorContent(opts.prompt); err != nil {
return err
}
} else {
if err := gui.renderStringSync(gui.Views.Confirmation, opts.prompt); err != nil {
return err
}
}

gui.renderString(gui.Views.Confirmation, opts.prompt)

return gui.setKeyBindings(opts)
})
return nil
Expand Down
1 change: 0 additions & 1 deletion pkg/gui/discard_changes_menu_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (gui *Gui) handleCreateDiscardMenu() error {
{
displayString: gui.Tr.LcDiscardAllChanges,
onPress: func() error {
gui.Log.Warn("HA?")
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllChangesInFile).DiscardAllFileChanges(file); err != nil {
return gui.surfaceError(err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/gui/files_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,12 @@ func (gui *Gui) handleIgnoreFile() error {
}

func (gui *Gui) handleWIPCommitPress() error {
skipHookPreifx := gui.Config.GetUserConfig().Git.SkipHookPrefix
if skipHookPreifx == "" {
skipHookPrefix := gui.Config.GetUserConfig().Git.SkipHookPrefix
if skipHookPrefix == "" {
return gui.createErrorPanel(gui.Tr.SkipHookPrefixNotConfigured)
}

_ = gui.renderStringSync(gui.Views.CommitMessage, skipHookPreifx)
if err := gui.Views.CommitMessage.SetCursor(len(skipHookPreifx), 0); err != nil {
if err := gui.Views.CommitMessage.SetEditorContent(skipHookPrefix); err != nil {
return err
}

Expand Down
18 changes: 18 additions & 0 deletions vendor/github.com/jesseduffield/gocui/edit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions vendor/golang.org/x/sys/unix/syscall_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/golang.org/x/sys/unix/ztypes_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/internal/frame
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
# github.com/jesseduffield/gocui v0.3.1-0.20210412130453-de7bb5079f9f
# github.com/jesseduffield/gocui v0.3.1-0.20210417110745-37f79434200d
## explicit
github.com/jesseduffield/gocui
# github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe
Expand Down Expand Up @@ -235,7 +235,7 @@ golang.org/x/crypto/ssh/knownhosts
golang.org/x/net/context
golang.org/x/net/internal/socks
golang.org/x/net/proxy
# golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57
# golang.org/x/sys v0.0.0-20210415045647-66c3f260301c
## explicit
golang.org/x/sys/cpu
golang.org/x/sys/internal/unsafeheader
Expand Down

0 comments on commit b28b2d0

Please sign in to comment.