Skip to content

Commit 70cd6e1

Browse files
committed
feat: text input can now include a default value for tabbing
1 parent 12a297a commit 70cd6e1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

models/minitia/launch.go

+1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ func NewOpBridgeSubmissionIntervalInput(state *LaunchState) *OpBridgeSubmissionI
562562
question: "Please specify OP bridge config: Submission Interval (format m, h or d - ex. 1m, 23h, 7d)",
563563
}
564564
model.WithPlaceholder("Press tab to use “1m”")
565+
model.WithDefaultValue("1m")
565566
return model
566567
}
567568

utils/text_input.go

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type TextInput struct {
1212
Text string
1313
Cursor int // Cursor position within the text
1414
Placeholder string
15+
DefaultValue string
1516
ValidationFn func(string) error
1617
IsEntered bool
1718
}
@@ -21,6 +22,7 @@ func NewTextInput() TextInput {
2122
Text: "",
2223
Cursor: 0,
2324
Placeholder: "<todo: Jennie revisit placeholder>",
25+
DefaultValue: "",
2426
ValidationFn: NoOps,
2527
IsEntered: false,
2628
}
@@ -34,6 +36,10 @@ func (ti *TextInput) WithPlaceholder(placeholder string) {
3436
ti.Placeholder = placeholder
3537
}
3638

39+
func (ti *TextInput) WithDefaultValue(value string) {
40+
ti.DefaultValue = value
41+
}
42+
3743
func (ti TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd, bool) {
3844
switch msg := msg.(type) {
3945
case tea.KeyMsg:
@@ -51,6 +57,13 @@ func (ti TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd, bool) {
5157
ti.Cursor--
5258
}
5359

60+
case msg.Type == tea.KeyTab:
61+
ti.IsEntered = false
62+
if ti.Text == "" {
63+
ti.Text = ti.DefaultValue
64+
ti.Cursor = len(ti.Text)
65+
}
66+
5467
// Handle Option + Left (move one word left) - Detected as "alt+b"
5568
case msg.String() == "alt+b":
5669
ti.IsEntered = false

0 commit comments

Comments
 (0)