Skip to content

Commit

Permalink
feat: adds GetArg and GetWord methods to Buffer (#3112)
Browse files Browse the repository at this point in the history
  • Loading branch information
taconi authored Mar 12, 2024
1 parent 88b4498 commit fe4ade7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions internal/action/infocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// CommandComplete autocompletes commands
func CommandComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

var suggestions []string
for cmd := range commands {
Expand All @@ -38,7 +38,7 @@ func CommandComplete(b *buffer.Buffer) ([]string, []string) {
// HelpComplete autocompletes help topics
func HelpComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

var suggestions []string

Expand Down Expand Up @@ -107,7 +107,7 @@ func contains(s []string, e string) bool {
// OptionComplete autocompletes options
func OptionComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

var suggestions []string
for option := range config.GlobalSettings {
Expand All @@ -134,7 +134,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
l := b.LineBytes(c.Y)
l = util.SliceStart(l, c.X)
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

completeValue := false
args := bytes.Split(l, []byte{' '})
Expand Down Expand Up @@ -230,7 +230,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
// PluginCmdComplete autocompletes the plugin command
func PluginCmdComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

var suggestions []string
for _, cmd := range PluginCmds {
Expand All @@ -252,7 +252,7 @@ func PluginComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
l := b.LineBytes(c.Y)
l = util.SliceStart(l, c.X)
input, argstart := buffer.GetArg(b)
input, argstart := b.GetArg()

completeValue := false
args := bytes.Split(l, []byte{' '})
Expand Down
8 changes: 4 additions & 4 deletions internal/buffer/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (b *Buffer) CycleAutocomplete(forward bool) {

// GetWord gets the most recent word separated by any separator
// (whitespace, punctuation, any non alphanumeric character)
func GetWord(b *Buffer) ([]byte, int) {
func (b *Buffer) GetWord() ([]byte, int) {
c := b.GetActiveCursor()
l := b.LineBytes(c.Y)
l = util.SliceStart(l, c.X)
Expand All @@ -83,7 +83,7 @@ func GetWord(b *Buffer) ([]byte, int) {
}

// GetArg gets the most recent word (separated by ' ' only)
func GetArg(b *Buffer) (string, int) {
func (b *Buffer) GetArg() (string, int) {
c := b.GetActiveCursor()
l := b.LineBytes(c.Y)
l = util.SliceStart(l, c.X)
Expand All @@ -104,7 +104,7 @@ func GetArg(b *Buffer) (string, int) {
// FileComplete autocompletes filenames
func FileComplete(b *Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := GetArg(b)
input, argstart := b.GetArg()

sep := string(os.PathSeparator)
dirs := strings.Split(input, sep)
Expand Down Expand Up @@ -153,7 +153,7 @@ func FileComplete(b *Buffer) ([]string, []string) {
// BufferComplete autocompletes based on previous words in the buffer
func BufferComplete(b *Buffer) ([]string, []string) {
c := b.GetActiveCursor()
input, argstart := GetWord(b)
input, argstart := b.GetWord()

if argstart == -1 {
return []string{}, []string{}
Expand Down

0 comments on commit fe4ade7

Please sign in to comment.