You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**`button_index` is 1-based**, not 0-based. The first button returns `1`. This is consistent with Vim's built-in `confirm()`.
153
+
-**`button_index` is 0-based**. The first button returns `0`, the second returns `1`, and so on.
154
+
-**Distinguish Enter from button click using `button`.** When `button_index` is `0`, check `r.button`: if it is `''`, the user pressed Enter on a non-button control; if it is non-empty, the first button was clicked.
154
155
-**Cancel still returns values.** Even after ESC, `r.name` and other fields contain whatever the user typed before cancelling. This is useful if you want to restore state when reopening the dialog.
155
156
-**`button` tells you which button row was clicked.** If you have multiple button rows with different names, this field tells you which group the click came from.
156
157
@@ -159,7 +160,7 @@ In most cases, you just need this:
159
160
```vim
160
161
let r = quickui#dialog#open(items, opts)
161
162
162
-
if r.button_index >= 1
163
+
if r.button_index >= 0 && r.button != ''
163
164
" User clicked a button — do something with the values
164
165
echo 'Name: ' . r.name
165
166
endif
@@ -168,8 +169,8 @@ endif
168
169
Or if you have OK and Cancel buttons:
169
170
170
171
```vim
171
-
" ' &OK ' is button 1, ' &Cancel ' is button 2
172
-
if r.button_index == 1
172
+
" ' &OK ' is button 0, ' &Cancel ' is button 1
173
+
if r.button_index == 0 && r.button != ''
173
174
echo 'Accepted: ' . r.name
174
175
endif
175
176
```
@@ -204,8 +205,8 @@ function! NewProject()
204
205
let opts = {'title': 'New Project', 'w': 50, 'focus': 'project_name'}
205
206
let result = quickui#dialog#open(items, opts)
206
207
207
-
" Check if the user clicked "Create" (button 1)
208
-
if result.button_index == 1
208
+
" Check if the user clicked "Create" (button 0)
209
+
if result.button_index == 0 && result.button != ''
209
210
" dropdown returns an index — convert it to text
210
211
let languages = ['Python', 'JavaScript', 'Go', 'Rust', 'C++']
211
212
let builds = ['Make', 'CMake', 'Cargo', 'npm', 'pip']
0 commit comments