From a541e454e7fa811b1b2f1fe681a157280824609f Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Tue, 3 Oct 2023 04:10:52 +0900 Subject: [PATCH] Changed via method Stopped directly accessing the Candidate structure. --- oviewer/input.go | 15 +++++++++++++++ oviewer/input_delimiter.go | 3 +-- oviewer/input_goto.go | 3 +-- oviewer/input_jumptarget.go | 3 +-- oviewer/input_multicolor.go | 9 ++++----- oviewer/input_search.go | 14 ++++++-------- oviewer/input_section_delimiter.go | 3 +-- oviewer/input_section_start.go | 3 +-- oviewer/input_tabwidth.go | 3 +-- oviewer/input_watch.go | 3 +-- oviewer/input_writeba.go | 3 +-- 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/oviewer/input.go b/oviewer/input.go index 2dd18b5d..b054d8c5 100644 --- a/oviewer/input.go +++ b/oviewer/input.go @@ -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 { diff --git a/oviewer/input_delimiter.go b/oviewer/input_delimiter.go index 29ca5808..369b46d5 100644 --- a/oviewer/input_delimiter.go +++ b/oviewer/input_delimiter.go @@ -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 } diff --git a/oviewer/input_goto.go b/oviewer/input_goto.go index 95a7df62..ed9a9c69 100644 --- a/oviewer/input_goto.go +++ b/oviewer/input_goto.go @@ -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 } diff --git a/oviewer/input_jumptarget.go b/oviewer/input_jumptarget.go index d0a372e9..f4193578 100644 --- a/oviewer/input_jumptarget.go +++ b/oviewer/input_jumptarget.go @@ -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 } diff --git a/oviewer/input_multicolor.go b/oviewer/input_multicolor.go index a3e30a60..0b7735a4 100644 --- a/oviewer/input_multicolor.go +++ b/oviewer/input_multicolor.go @@ -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) } @@ -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() } diff --git a/oviewer/input_search.go b/oviewer/input_search.go index 0fec0654..1cd04d10 100644 --- a/oviewer/input_search.go +++ b/oviewer/input_search.go @@ -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() } @@ -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() } diff --git a/oviewer/input_section_delimiter.go b/oviewer/input_section_delimiter.go index ba88a530..ee99a374 100644 --- a/oviewer/input_section_delimiter.go +++ b/oviewer/input_section_delimiter.go @@ -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 } diff --git a/oviewer/input_section_start.go b/oviewer/input_section_start.go index fd52a6b2..4fcfb049 100644 --- a/oviewer/input_section_start.go +++ b/oviewer/input_section_start.go @@ -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 } diff --git a/oviewer/input_tabwidth.go b/oviewer/input_tabwidth.go index a1e7e315..a76359a3 100644 --- a/oviewer/input_tabwidth.go +++ b/oviewer/input_tabwidth.go @@ -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 } diff --git a/oviewer/input_watch.go b/oviewer/input_watch.go index 025ec15c..74ff97db 100644 --- a/oviewer/input_watch.go +++ b/oviewer/input_watch.go @@ -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 } diff --git a/oviewer/input_writeba.go b/oviewer/input_writeba.go index 4871e68c..9ac3d7b4 100644 --- a/oviewer/input_writeba.go +++ b/oviewer/input_writeba.go @@ -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 }