-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extend lastcmd mode to support all the previous cmds #1831
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ type ListBoxSpec struct { | |
OnSelect func(it Items, i int) | ||
// A function called on the accept event. | ||
OnAccept func(it Items, i int) | ||
// A function called when selecting before the beginning of the items. | ||
OnUnderFlow func(ListBox) | ||
// A function called when selecting after the ending of the items. | ||
OnOverFlow func(ListBox) | ||
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are misnomers that they're no longer triggered when underflow/overflow. Maybe |
||
// Whether the listbox should be rendered in a horizontal layout. Note that | ||
// in the horizontal layout, items must have only one line. | ||
Horizontal bool | ||
|
@@ -65,6 +69,12 @@ func NewListBox(spec ListBoxSpec) ListBox { | |
if spec.OnAccept == nil { | ||
spec.OnAccept = func(Items, int) {} | ||
} | ||
if spec.OnUnderFlow == nil { | ||
spec.OnUnderFlow = func(ListBox) {} | ||
} | ||
if spec.OnOverFlow == nil { | ||
spec.OnOverFlow = func(ListBox) {} | ||
} | ||
if spec.OnSelect == nil { | ||
spec.OnSelect = func(Items, int) {} | ||
} else { | ||
|
@@ -284,6 +294,12 @@ func (w *listBox) Handle(event term.Event) bool { | |
case term.K(ui.Enter): | ||
w.Accept() | ||
return true | ||
case term.K(ui.Up, ui.Alt): | ||
w.OnUnderFlow(w) | ||
return true | ||
case term.K(ui.Down, ui.Alt): | ||
w.OnOverFlow(w) | ||
return true | ||
Comment on lines
+297
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nicer if this is part of the keybinding rather than hardcoded in the event handler. |
||
} | ||
return false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be called
getItems
- also the choice of makingc
an argument seems arbitrary, it's always the same argument