Skip to content

Commit

Permalink
Merge pull request #448 from noborus/improve-candidate
Browse files Browse the repository at this point in the history
Changed via method
  • Loading branch information
noborus authored Oct 2, 2023
2 parents 23db449 + a541e45 commit 3fb7dba
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
15 changes: 15 additions & 0 deletions oviewer/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ type candidate struct {
p int
}

func (c *candidate) toLast(str string) {
c.list = toLast(c.list, str)
c.p = 0
}

func (c *candidate) toAddTop(str string) {
c.list = toAddTop(c.list, str)
c.p = 0
}

func (c *candidate) toAddLast(str string) {
c.list = toAddLast(c.list, str)
c.p = 0
}

// up returns the previous candidate.
func (c *candidate) up() string {
if len(c.list) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func (e *eventDelimiter) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventDelimiter) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_goto.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (e *eventGoto) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventGoto) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_jumptarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (e *eventJumpTarget) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventJumpTarget) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
9 changes: 4 additions & 5 deletions oviewer/input_multicolor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (root *Root) setMultiColorMode() {

list := root.searchCandidates(searchCandidateListLen)
str := strings.Join(list, " ")
input.MultiColorCandidate.list = toLast(input.MultiColorCandidate.list, str)
input.MultiColorCandidate.toLast(str)

input.Event = newMultiColorEvent(input.MultiColorCandidate)
}
Expand Down Expand Up @@ -57,20 +57,19 @@ func (e *eventMultiColor) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventMultiColor) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}

// Up returns strings when the up key is pressed during input.
func (e *eventMultiColor) Up(str string) string {
e.clist.list = toAddLast(e.clist.list, str)
e.clist.toAddLast(str)
return e.clist.up()
}

// Down returns strings when the down key is pressed during input.
func (e *eventMultiColor) Down(str string) string {
e.clist.list = toAddTop(e.clist.list, str)
e.clist.toAddTop(str)
return e.clist.down()
}
14 changes: 6 additions & 8 deletions oviewer/input_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ func (e *eventInputSearch) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventInputSearch) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}

// Up returns strings when the up key is pressed during input.
func (e *eventInputSearch) Up(str string) string {
e.clist.list = toAddLast(e.clist.list, str)
e.clist.toAddLast(str)
return e.clist.up()
}

// Down returns strings when the down key is pressed during input.
func (e *eventInputSearch) Down(str string) string {
e.clist.list = toAddTop(e.clist.list, str)
e.clist.toAddTop(str)
return e.clist.down()
}

Expand Down Expand Up @@ -98,21 +97,20 @@ func (e *eventInputBackSearch) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventInputBackSearch) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}

// Up returns strings when the up key is pressed during input.
func (e *eventInputBackSearch) Up(str string) string {
e.clist.list = toAddLast(e.clist.list, str)
e.clist.toAddLast(str)
return e.clist.up()
}

// Down returns strings when the down key is pressed during input.
func (e *eventInputBackSearch) Down(str string) string {
e.clist.list = toAddTop(e.clist.list, str)
e.clist.toAddTop(str)
return e.clist.down()
}

Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_section_delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func (e *eventSectionDelimiter) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventSectionDelimiter) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_section_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func (e *eventSectionStart) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventSectionStart) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_tabwidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func (e *eventTabWidth) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventTabWidth) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func (e *eventWatchInterval) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventWatchInterval) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down
3 changes: 1 addition & 2 deletions oviewer/input_writeba.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (e *eventWriteBA) Prompt() string {
// Confirm returns the event when the input is confirmed.
func (e *eventWriteBA) Confirm(str string) tcell.Event {
e.value = str
e.clist.list = toLast(e.clist.list, str)
e.clist.p = 0
e.clist.toLast(str)
e.SetEventNow()
return e
}
Expand Down

0 comments on commit 3fb7dba

Please sign in to comment.