@juicesharp/rpiv-ask-user-question 2.13.5 → 2.13.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/docs/hosts.md +4 -4
- package/docs/keyboard.md +18 -12
- package/docs/tool-schema.md +2 -2
- package/locales/de.json +3 -1
- package/locales/en.json +3 -1
- package/locales/es.json +3 -1
- package/locales/fr.json +3 -1
- package/locales/pt-BR.json +3 -1
- package/locales/pt.json +3 -1
- package/locales/ru.json +3 -1
- package/locales/uk.json +3 -1
- package/locales/zh.json +3 -1
- package/package.json +2 -2
- package/rpc-fallback.ts +19 -14
- package/state/key-router.ts +15 -13
- package/state/selectors/derivations.ts +15 -0
- package/state/selectors/projections.ts +4 -1
- package/state/state-reducer.ts +29 -18
- package/tool/format-answer.ts +5 -2
- package/tool/types.ts +3 -2
- package/view/components/multi-select-view.ts +4 -2
- package/view/components/preview/preview-block-renderer.ts +22 -12
- package/view/components/preview/preview-pane.ts +17 -12
- package/view/dialog-builder.ts +6 -1
- package/view/tab-content-strategy.ts +26 -7
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Nothing to set up — the tool is live as soon as Pi restarts. Hand the model a
|
|
|
25
25
|
|
|
26
26
|
> Add caching to the API client.
|
|
27
27
|
|
|
28
|
-
Rather than picking a strategy on your behalf, the model calls `ask_user_question` and a dialog takes over the bottom of your terminal. Move with `↑`/`↓`, choose with `Enter`, press `n` to attach a note to a question
|
|
28
|
+
Rather than picking a strategy on your behalf, the model calls `ask_user_question` and a dialog takes over the bottom of your terminal. Move with `↑`/`↓`, choose with `Enter`, press `n` to attach a note to a question or a global note from the Submit tab, or land on `Type something.` to answer in your own words. In a multi-select question, typed custom text is selected automatically and submitted together with checked options. While typing, `Shift+Enter` adds a line, `Ctrl+G` opens Pi's configured external editor, and `Ctrl+U` clears the draft; browsing another option and returning keeps what you wrote. `Esc` abandons the questionnaire entirely.
|
|
29
29
|
|
|
30
30
|
When the questionnaire begins waiting in an interactive TTY, it emits one standard terminal BEL (`\x07`). Your terminal configuration determines whether that appears as an audible alert, a visual alert, or nothing; redirected and non-TTY output is untouched.
|
|
31
31
|
|
|
@@ -38,7 +38,7 @@ When the model asks several things at once, `Tab` moves between them and a Submi
|
|
|
38
38
|
## What you get
|
|
39
39
|
|
|
40
40
|
- **Typed options instead of a wall of prose** — each question carries 2-4 authored choices, and every choice comes with a description of what it means or what it costs you.
|
|
41
|
-
- **You can always answer in your own words
|
|
41
|
+
- **You can always answer in your own words**. A `Type something.` row is appended to every question. On multi-select questions, it keeps checked options and custom text in the same answer. The row widens to the full pane while you type, keeps its multiline draft visible while you browse, and supports Pi's `Shift+Enter` newline and `Ctrl+G` external-editor flows.
|
|
42
42
|
- **Compare real artifacts, not just labels** — an option can carry a markdown `preview` (ASCII mockup, code, diagram, config) that renders in a bordered box beside the option list.
|
|
43
43
|
- **One interruption, not five** — up to four questions arrive in a single tabbed dialog, and the Submit tab lists your answers and names anything still blank before you commit.
|
|
44
44
|
- **Notes on any answer — or on all of them** — `n` opens a multiline note editor on any question tab, and on the Submit tab it opens one global note for the whole questionnaire. Per-question notes reach the model as `user notes: <text>`, the global note as `global note: <text>`; neither marks a question answered.
|
package/docs/hosts.md
CHANGED
|
@@ -46,10 +46,10 @@ TUI produces. Trade-offs inherent to the native primitives:
|
|
|
46
46
|
- No notes. Both note kinds — per-question `n` on a question tab and global `n` on the
|
|
47
47
|
Submit tab — are terminal-only; the host's native `select` and `input` primitives carry
|
|
48
48
|
no note field.
|
|
49
|
-
- Multi-select is a free-text input
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
- Multi-select is a free-text input. Type option numbers separated by commas (`1,3`).
|
|
50
|
+
Add a semicolon and custom text to return both (`1,3; another color`). Plain text still
|
|
51
|
+
returns a custom-only multi-select answer. An empty input commits an empty selection,
|
|
52
|
+
matching `Next` with nothing selected.
|
|
53
53
|
- Dismissing any dialog cancels the whole questionnaire, mirroring `Esc` in the TUI.
|
|
54
54
|
|
|
55
55
|
If the host can render neither custom UI nor dialogs, the call returns
|
package/docs/keyboard.md
CHANGED
|
@@ -12,7 +12,7 @@ adapts to the size of your terminal.
|
|
|
12
12
|
| `Shift+Enter` | Insert a newline. | `Type something.` input, notes editor |
|
|
13
13
|
| `Esc` | Cancel the whole questionnaire. | Everywhere except the notes editor, where it closes notes |
|
|
14
14
|
| `Tab` / `Shift+Tab` | Next / previous tab, wrapping. `→` / `←` do the same. | Multi-question dialogs only |
|
|
15
|
-
| `Space` | Toggle the focused
|
|
15
|
+
| `Space` | Toggle the focused authored option. In `Type something.`, Space inserts text. | Multi-select questions |
|
|
16
16
|
| `n` | Open the notes editor for the focused question — or, on the Submit tab, the global note for the whole questionnaire. | Every question tab; the Submit tab in multi-question dialogs |
|
|
17
17
|
| `Ctrl+G` | Open Pi's configured external editor with the current custom-answer draft. | `Type something.` input |
|
|
18
18
|
| `Ctrl+U` | Clear the current custom-answer draft. | `Type something.` input |
|
|
@@ -26,13 +26,13 @@ Slack-style configuration — `enter` folded into `tui.input.newLine`, submit mo
|
|
|
26
26
|
everywhere `Enter` does.
|
|
27
27
|
|
|
28
28
|
In a multi-select question, `Enter` on a regular row toggles its checkbox exactly like
|
|
29
|
-
`Space
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
`Space`. It does not submit. Focus `Next` and press `Enter` to commit the question. That
|
|
30
|
+
is deliberate: it makes `Enter` a zero-cost way to flip boxes without leaving the home row.
|
|
31
|
+
`Space` does nothing on `Next` (it is a command, not a choice).
|
|
32
32
|
|
|
33
|
-
`
|
|
34
|
-
`
|
|
35
|
-
|
|
33
|
+
`Type something.` is an inline input, so Space inserts a space. Its checkbox changes to
|
|
34
|
+
`[✔]` when the input contains text. Press `Enter` in the input or use `Next` to submit
|
|
35
|
+
both the checked options and the custom text.
|
|
36
36
|
|
|
37
37
|
## The rows the dialog adds
|
|
38
38
|
|
|
@@ -43,12 +43,15 @@ answer).
|
|
|
43
43
|
|
|
44
44
|
Focusing `Type something.` switches the row into an inline multiline editor. In preview
|
|
45
45
|
mode it expands to the full pane width while you type, so a long custom answer is not
|
|
46
|
-
squeezed into the narrow options column. `Shift+Enter` inserts a line break
|
|
46
|
+
squeezed into the narrow options column. `Shift+Enter` inserts a line break. Vertical
|
|
47
47
|
arrows move between lines and return to row navigation at the draft's top and bottom.
|
|
48
48
|
The draft replaces the static row label while you browse other options and is isolated
|
|
49
|
-
per question. `Ctrl+G`
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
per question. `Ctrl+G` sends it through Pi's configured external editor. `Ctrl+U` clears
|
|
50
|
+
it, while `Esc` cancels the questionnaire.
|
|
51
|
+
|
|
52
|
+
On a single-select question, confirming the input produces `kind: "custom"`. On a
|
|
53
|
+
multi-select question, the result uses `kind: "multi"`: `selected` contains checked
|
|
54
|
+
labels, and `answer` contains the custom text.
|
|
52
55
|
|
|
53
56
|
Both labels are reserved — the model cannot author an option that collides with them.
|
|
54
57
|
Both localize with the rest of the UI chrome; the reserved-label check always compares
|
|
@@ -60,7 +63,10 @@ against the canonical English strings.
|
|
|
60
63
|
multi-select and whether or not its options carry previews. Notes are stored in a
|
|
61
64
|
side-band keyed by tab index, not inside the answer, so writing a note does not mark a
|
|
62
65
|
question as answered — the Submit tab still lists it as outstanding. The note merges into
|
|
63
|
-
the answer when you confirm it, and reaches the model as `user notes: <text>`.
|
|
66
|
+
the answer when you confirm it, and reaches the model as `user notes: <text>`. Once the
|
|
67
|
+
editor closes, the question shows the saved note as `Note for this answer: …` (its first
|
|
68
|
+
line), and a preview pane's hint changes to "Note saved: press n to edit"; the Submit tab's
|
|
69
|
+
review uses the same label.
|
|
64
70
|
|
|
65
71
|
On the Submit tab, `n` opens the global note editor instead — one note covering the whole
|
|
66
72
|
questionnaire. It lives outside every answer, so it survives tab switches and never marks
|
package/docs/tool-schema.md
CHANGED
|
@@ -77,8 +77,8 @@ code. The `content[0].text` string is written for the model, not for a log.
|
|
|
77
77
|
questionIndex: number,
|
|
78
78
|
question: string,
|
|
79
79
|
kind: "option" | "custom" | "multi",
|
|
80
|
-
answer: string | null, // option label,
|
|
81
|
-
selected?: string[], // chosen labels, multi-select only
|
|
80
|
+
answer: string | null, // option label, custom text, or null
|
|
81
|
+
selected?: string[], // chosen labels, multi-select only; can accompany answer
|
|
82
82
|
notes?: string, // free-text note, when you wrote one
|
|
83
83
|
preview?: string, // echoed back when the chosen option carried a preview
|
|
84
84
|
}>,
|
package/locales/de.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Keine Vorschau verfügbar",
|
|
24
24
|
"preview.notes_affordance": "Notizen: drücke n, um Notizen hinzuzufügen",
|
|
25
|
+
"preview.notes_edit_affordance": "Notiz gespeichert: drücke n zum Bearbeiten",
|
|
25
26
|
"notes.header": "Notizen:",
|
|
27
|
+
"notes.saved_label": "Notiz zu dieser Antwort:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Externer Editor fehlgeschlagen",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch
|
|
31
|
+
"rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Kommas getrennt ein (z. B. \"1,3\"). Füge \"; eigene Antwort\" hinzu, um eigenen Text einzuschließen, oder gib nur eigenen Text ein.",
|
|
30
32
|
"rpc.custom_answer_title": "Gib deine Antwort ein:"
|
|
31
33
|
}
|
package/locales/en.json
CHANGED
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
|
|
25
25
|
"preview.no_preview": "No preview available",
|
|
26
26
|
"preview.notes_affordance": "Notes: press n to add notes",
|
|
27
|
+
"preview.notes_edit_affordance": "Note saved: press n to edit",
|
|
27
28
|
"notes.header": "Notes:",
|
|
29
|
+
"notes.saved_label": "Note for this answer:",
|
|
28
30
|
"notes.global_header": "Global note:",
|
|
29
31
|
|
|
30
32
|
"editor.failed": "External editor failed",
|
|
31
33
|
|
|
32
|
-
"rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\")
|
|
34
|
+
"rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"). Add \"; custom answer\" to include your own text, or type only custom text.",
|
|
33
35
|
"rpc.custom_answer_title": "Type your answer:"
|
|
34
36
|
}
|
package/locales/es.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Vista previa no disponible",
|
|
24
24
|
"preview.notes_affordance": "Notas: pulsa n para añadir notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota guardada: pulsa n para editarla",
|
|
25
26
|
"notes.header": "Notas:",
|
|
27
|
+
"notes.saved_label": "Nota para esta respuesta:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Error del editor externo",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Introduce los números de todas las opciones que
|
|
31
|
+
"rpc.multi_instructions": "Introduce los números de todas las opciones que correspondan, separados por comas (p. ej. \"1,3\"). Añade \"; respuesta propia\" para incluir texto propio, o escribe solo texto propio.",
|
|
30
32
|
"rpc.custom_answer_title": "Escribe tu respuesta:"
|
|
31
33
|
}
|
package/locales/fr.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Aucun aperçu disponible",
|
|
24
24
|
"preview.notes_affordance": "Notes : appuyez sur n pour ajouter des notes",
|
|
25
|
+
"preview.notes_edit_affordance": "Note enregistrée : appuyez sur n pour la modifier",
|
|
25
26
|
"notes.header": "Notes :",
|
|
27
|
+
"notes.saved_label": "Note pour cette réponse :",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Échec de l’éditeur externe",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »)
|
|
31
|
+
"rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »). Ajoutez « ; réponse libre » pour inclure votre propre texte, ou saisissez uniquement ce texte.",
|
|
30
32
|
"rpc.custom_answer_title": "Tapez votre réponse :"
|
|
31
33
|
}
|
package/locales/pt-BR.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Pré-visualização indisponível",
|
|
24
24
|
"preview.notes_affordance": "Notas: pressione n para adicionar notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota salva: pressione n para editar",
|
|
25
26
|
"notes.header": "Notas:",
|
|
27
|
+
"notes.saved_label": "Nota para esta resposta:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Falha no editor externo",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por
|
|
31
|
+
"rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou digite apenas esse texto.",
|
|
30
32
|
"rpc.custom_answer_title": "Digite sua resposta:"
|
|
31
33
|
}
|
package/locales/pt.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Pré-visualização indisponível",
|
|
24
24
|
"preview.notes_affordance": "Notas: prima n para adicionar notas",
|
|
25
|
+
"preview.notes_edit_affordance": "Nota guardada: prima n para editar",
|
|
25
26
|
"notes.header": "Notas:",
|
|
27
|
+
"notes.saved_label": "Nota para esta resposta:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Falha no editor externo",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\")
|
|
31
|
+
"rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou escreva apenas esse texto.",
|
|
30
32
|
"rpc.custom_answer_title": "Escreva a sua resposta:"
|
|
31
33
|
}
|
package/locales/ru.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Предпросмотр недоступен",
|
|
24
24
|
"preview.notes_affordance": "Заметки: нажмите n, чтобы добавить заметки",
|
|
25
|
+
"preview.notes_edit_affordance": "Заметка сохранена: нажмите n, чтобы изменить",
|
|
25
26
|
"notes.header": "Заметки:",
|
|
27
|
+
"notes.saved_label": "Заметка к этому ответу:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Ошибка внешнего редактора",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\") или введите
|
|
31
|
+
"rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\"). Добавьте \"; свой ответ\", чтобы включить собственный текст, или введите только этот текст.",
|
|
30
32
|
"rpc.custom_answer_title": "Введите свой ответ:"
|
|
31
33
|
}
|
package/locales/uk.json
CHANGED
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
"preview.no_preview": "Попередній перегляд недоступний",
|
|
24
24
|
"preview.notes_affordance": "Нотатки: натисніть n, щоб додати нотатки",
|
|
25
|
+
"preview.notes_edit_affordance": "Нотатку збережено: натисніть n, щоб змінити",
|
|
25
26
|
"notes.header": "Нотатки:",
|
|
27
|
+
"notes.saved_label": "Нотатка до цієї відповіді:",
|
|
26
28
|
|
|
27
29
|
"editor.failed": "Помилка зовнішнього редактора",
|
|
28
30
|
|
|
29
|
-
"rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\") або введіть
|
|
31
|
+
"rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\"). Додайте \"; власна відповідь\", щоб включити власний текст, або введіть лише цей текст.",
|
|
30
32
|
"rpc.custom_answer_title": "Введіть свою відповідь:"
|
|
31
33
|
}
|
package/locales/zh.json
CHANGED
|
@@ -24,10 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
"preview.no_preview": "暂无预览",
|
|
26
26
|
"preview.notes_affordance": "备注:按 n 添加",
|
|
27
|
+
"preview.notes_edit_affordance": "备注已保存:按 n 编辑",
|
|
27
28
|
"notes.header": "备注:",
|
|
29
|
+
"notes.saved_label": "此回答的备注:",
|
|
28
30
|
|
|
29
31
|
"editor.failed": "外部编辑器启动失败",
|
|
30
32
|
|
|
31
|
-
"rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\"
|
|
33
|
+
"rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\")。添加 \"; 自定义回答\" 可同时包含自定义文本,也可以只输入自定义文本。",
|
|
32
34
|
"rpc.custom_answer_title": "输入你的回答:"
|
|
33
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.7",
|
|
4
4
|
"description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -99,6 +99,6 @@
|
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
|
-
"@juicesharp/rpiv-config": "^2.13.
|
|
102
|
+
"@juicesharp/rpiv-config": "^2.13.7"
|
|
103
103
|
}
|
|
104
104
|
}
|
package/rpc-fallback.ts
CHANGED
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
* Parity trade-offs vs the TUI, inherent to the select/input API surface: no
|
|
15
15
|
* side-by-side preview pane (previews are folded into the prompt title), no
|
|
16
16
|
* tabbed multi-question review (one dialog per question), and multi-select is
|
|
17
|
-
* a free-text numbers input instead of checkbox rows. The
|
|
18
|
-
*
|
|
19
|
-
* input as a typed custom answer — matching
|
|
20
|
-
* `ROW_INTENT_META.other.autoAppendOnMultiSelect`.
|
|
17
|
+
* a free-text numbers input instead of checkbox rows. The input accepts selected
|
|
18
|
+
* option numbers, custom text, or both separated by a semicolon.
|
|
21
19
|
*/
|
|
22
20
|
|
|
23
21
|
import { displayLabel, t } from "./state/i18n-bridge.js";
|
|
@@ -30,9 +28,9 @@ import type { QuestionAnswer, QuestionData, QuestionnaireResult, QuestionParams
|
|
|
30
28
|
* `displayLabel("other")` — same source as the TUI row.
|
|
31
29
|
*/
|
|
32
30
|
const MULTI_SELECT_INSTRUCTIONS =
|
|
33
|
-
'Enter the numbers of all that apply, comma-separated (e.g. "1,3")
|
|
31
|
+
'Enter the numbers of all that apply, comma-separated (e.g. "1,3"). Add "; custom answer" to include your own text, or type only custom text.';
|
|
34
32
|
const CUSTOM_ANSWER_TITLE = "Type your answer:";
|
|
35
|
-
const MULTI_SELECT_PLACEHOLDER = "1,3";
|
|
33
|
+
const MULTI_SELECT_PLACEHOLDER = "1,3; custom answer";
|
|
36
34
|
|
|
37
35
|
/** Longest preview slice folded into a select title before truncation. */
|
|
38
36
|
const MAX_PREVIEW_CHARS = 600;
|
|
@@ -180,19 +178,26 @@ async function askMultiSelect(
|
|
|
180
178
|
// Deliberate empty commit — same as pressing "Next" with nothing toggled.
|
|
181
179
|
return { questionIndex, question: q.question, kind: "multi", answer: null, selected: [] };
|
|
182
180
|
}
|
|
183
|
-
const
|
|
181
|
+
const [selectionPart = "", ...customParts] = trimmed.split(";");
|
|
182
|
+
const selection = selectionPart.trim();
|
|
183
|
+
const custom = customParts.join(";").trim();
|
|
184
|
+
const tokens = selection.split(/[,\s]+/).filter((tok) => tok.length > 0);
|
|
184
185
|
const indices = tokens.map((tok) => (/^\d+\.?$/.test(tok) ? parseIndex(tok, q.options.length) : null));
|
|
185
|
-
if (indices.every((i): i is number => i != null)) {
|
|
186
|
+
if (selection.length === 0 || indices.every((i): i is number => i != null)) {
|
|
186
187
|
const selected: string[] = [];
|
|
187
188
|
for (const i of indices) {
|
|
189
|
+
if (i == null) continue;
|
|
188
190
|
const label = q.options[i].label;
|
|
189
191
|
if (!selected.includes(label)) selected.push(label);
|
|
190
192
|
}
|
|
191
|
-
return {
|
|
193
|
+
return {
|
|
194
|
+
questionIndex,
|
|
195
|
+
question: q.question,
|
|
196
|
+
kind: "multi",
|
|
197
|
+
answer: custom.length > 0 ? custom : null,
|
|
198
|
+
selected,
|
|
199
|
+
};
|
|
192
200
|
}
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
// verbatim as a custom answer instead of silently dropping their input —
|
|
196
|
-
// this is also the multi-select "Type something." escape.
|
|
197
|
-
return { questionIndex, question: q.question, kind: "custom", answer: trimmed };
|
|
201
|
+
// Preserve unparseable input verbatim as custom text rather than dropping it.
|
|
202
|
+
return { questionIndex, question: q.question, kind: "multi", answer: trimmed, selected: [] };
|
|
198
203
|
}
|
package/state/key-router.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type QuestionnaireAction =
|
|
|
25
25
|
| { kind: "tab_switch"; nextTab: number }
|
|
26
26
|
| { kind: "confirm"; answer: QuestionAnswer; autoAdvanceTab?: number }
|
|
27
27
|
| { kind: "toggle"; index: number }
|
|
28
|
-
| { kind: "multi_confirm"; selected: string[]; autoAdvanceTab?: number }
|
|
28
|
+
| { kind: "multi_confirm"; selected: string[]; answer: string | null; autoAdvanceTab?: number }
|
|
29
29
|
| { kind: "cancel" }
|
|
30
30
|
| { kind: "notes_enter" }
|
|
31
31
|
| { kind: "notes_exit" }
|
|
@@ -116,6 +116,15 @@ function buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRun
|
|
|
116
116
|
return out;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
function buildMultiConfirmAction(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
|
|
120
|
+
return {
|
|
121
|
+
kind: "multi_confirm",
|
|
122
|
+
selected: buildMultiSelected(state, runtime),
|
|
123
|
+
answer: runtime.inputBuffer.trim().length > 0 ? runtime.inputBuffer : null,
|
|
124
|
+
autoAdvanceTab: computeAutoAdvanceTab(state, runtime),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
119
128
|
function tabSwitchAction(
|
|
120
129
|
data: string,
|
|
121
130
|
state: QuestionnaireState,
|
|
@@ -175,6 +184,8 @@ function routeInputMode(
|
|
|
175
184
|
// the same physical key to both semantic actions.
|
|
176
185
|
if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "ignore" };
|
|
177
186
|
if (isConfirm(kb, data)) {
|
|
187
|
+
const q = runtime.questions[state.currentTab];
|
|
188
|
+
if (q?.multiSelect) return buildMultiConfirmAction(state, runtime);
|
|
178
189
|
const answer = buildSingleSelectAnswer(state, runtime);
|
|
179
190
|
if (!answer) return { kind: "ignore" };
|
|
180
191
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|
|
@@ -241,24 +252,15 @@ function routeMultiSelectTab(
|
|
|
241
252
|
return { kind: "toggle", index: state.optionIndex };
|
|
242
253
|
}
|
|
243
254
|
if (isConfirm(kb, data)) {
|
|
244
|
-
// Enter on the "Type something." row is handled by the inputMode block above
|
|
245
|
-
//
|
|
246
|
-
// path for an inputMode-activating row.
|
|
255
|
+
// Enter on the "Type something." row is handled by the inputMode block above.
|
|
256
|
+
// Defensive: never enter the toggle/multi_confirm path for an input-mode row.
|
|
247
257
|
if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
|
|
248
258
|
// Enter on a regular row toggles (matching Space) — committing the question is now
|
|
249
259
|
// gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`
|
|
250
260
|
// (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes
|
|
251
261
|
// without leaving the keyboard home row.
|
|
252
262
|
if (!focusedMeta?.autoSubmitsInMulti) return { kind: "toggle", index: state.optionIndex };
|
|
253
|
-
|
|
254
|
-
// multi-question mode, OR submit the dialog in single-question mode
|
|
255
|
-
// (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select
|
|
256
|
-
// question would have no way to commit at all.
|
|
257
|
-
return {
|
|
258
|
-
kind: "multi_confirm",
|
|
259
|
-
selected: buildMultiSelected(state, runtime),
|
|
260
|
-
autoAdvanceTab: computeAutoAdvanceTab(state, runtime),
|
|
261
|
-
};
|
|
263
|
+
return buildMultiConfirmAction(state, runtime);
|
|
262
264
|
}
|
|
263
265
|
if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
|
|
264
266
|
return { kind: "ignore" };
|
|
@@ -38,3 +38,18 @@ export function selectActivePreviewPaneIndex(currentTab: number, totalQuestions:
|
|
|
38
38
|
if (totalQuestions <= 0) return 0;
|
|
39
39
|
return Math.min(currentTab, totalQuestions - 1);
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The committed note for a question tab, or `undefined` when it has none. Same precedence as
|
|
44
|
+
* the reducer's editor seeding (`notesValueFor`): the in-flight side-band (`notesByTab`) is
|
|
45
|
+
* authoritative — a note saved before the question is answered lives only there, and a
|
|
46
|
+
* present empty string means the note was cleared — with `answer.notes` as the mirror.
|
|
47
|
+
*/
|
|
48
|
+
export function selectSavedNote(
|
|
49
|
+
notesByTab: ReadonlyMap<number, string>,
|
|
50
|
+
answers: ReadonlyMap<number, QuestionAnswer>,
|
|
51
|
+
tab: number,
|
|
52
|
+
): string | undefined {
|
|
53
|
+
const note = notesByTab.get(tab) ?? answers.get(tab)?.notes;
|
|
54
|
+
return note && note.length > 0 ? note : undefined;
|
|
55
|
+
}
|
|
@@ -6,13 +6,14 @@ import type { TabBarProps } from "../../view/components/tab-bar.js";
|
|
|
6
6
|
import type { DialogProps } from "../../view/dialog-builder.js";
|
|
7
7
|
import { displayLabel } from "../i18n-bridge.js";
|
|
8
8
|
import type { GlobalSelector, PerTabBindingContext, PerTabSelector } from "./contract.js";
|
|
9
|
-
import { selectConfirmedIndicator } from "./derivations.js";
|
|
9
|
+
import { selectConfirmedIndicator, selectSavedNote } from "./derivations.js";
|
|
10
10
|
|
|
11
11
|
function emptyMultiSelectProps(ctx: PerTabBindingContext): MultiSelectViewProps {
|
|
12
12
|
return {
|
|
13
13
|
rows: [],
|
|
14
14
|
other: {
|
|
15
15
|
active: false,
|
|
16
|
+
checked: false,
|
|
16
17
|
inputMode: false,
|
|
17
18
|
inputBuffer: ctx.inputBuffer,
|
|
18
19
|
inputCursorOffset: ctx.inputCursorOffset,
|
|
@@ -46,6 +47,7 @@ export const selectMultiSelectProps: PerTabSelector<MultiSelectViewProps> = (sta
|
|
|
46
47
|
rows,
|
|
47
48
|
other: {
|
|
48
49
|
active: otherActive,
|
|
50
|
+
checked: ctx.inputBuffer.trim().length > 0,
|
|
49
51
|
inputMode: state.inputMode,
|
|
50
52
|
inputBuffer: ctx.inputBuffer,
|
|
51
53
|
inputCursorOffset: ctx.inputCursorOffset,
|
|
@@ -80,6 +82,7 @@ export const selectSubmitPickerProps: GlobalSelector<SubmitPickerProps> = (state
|
|
|
80
82
|
|
|
81
83
|
export const selectPreviewPaneProps: PerTabSelector<PreviewPaneProps> = (state, ctx) => ({
|
|
82
84
|
notesVisible: state.notesVisible,
|
|
85
|
+
hasNote: selectSavedNote(state.notesByTab, state.answers, ctx.i) !== undefined,
|
|
83
86
|
selectedIndex: state.optionIndex,
|
|
84
87
|
focused: ctx.activeView === "options",
|
|
85
88
|
inputMode: state.inputMode,
|
package/state/state-reducer.ts
CHANGED
|
@@ -63,15 +63,22 @@ function syncMultiSelectFromAnswers(
|
|
|
63
63
|
return indices;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
function selectedLabels(state: QuestionnaireState, question: QuestionData): string[] {
|
|
67
|
+
const selected: string[] = [];
|
|
68
|
+
for (let i = 0; i < question.options.length; i++) {
|
|
69
|
+
if (state.multiSelectChecked.has(i)) selected.push(question.options[i]!.label);
|
|
70
|
+
}
|
|
71
|
+
return selected;
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
function persistMultiSelectAnswer(state: QuestionnaireState, ctx: ApplyContext): ReadonlyMap<number, QuestionAnswer> {
|
|
67
75
|
const q = ctx.questions[state.currentTab];
|
|
68
76
|
if (!q?.multiSelect) return state.answers;
|
|
69
|
-
const selected
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
77
|
+
const selected = selectedLabels(state, q);
|
|
78
|
+
const custom = customDraftValueFor(state, state.currentTab);
|
|
79
|
+
const hasCustom = custom.trim().length > 0;
|
|
73
80
|
const out = new Map(state.answers);
|
|
74
|
-
if (selected.length === 0) {
|
|
81
|
+
if (selected.length === 0 && !hasCustom) {
|
|
75
82
|
out.delete(state.currentTab);
|
|
76
83
|
return out;
|
|
77
84
|
}
|
|
@@ -80,7 +87,7 @@ function persistMultiSelectAnswer(state: QuestionnaireState, ctx: ApplyContext):
|
|
|
80
87
|
questionIndex: state.currentTab,
|
|
81
88
|
question: q.question,
|
|
82
89
|
kind: "multi",
|
|
83
|
-
answer: null,
|
|
90
|
+
answer: hasCustom ? custom : null,
|
|
84
91
|
selected,
|
|
85
92
|
...(pendingNotes && pendingNotes.length > 0 ? { notes: pendingNotes } : {}),
|
|
86
93
|
});
|
|
@@ -100,7 +107,8 @@ function customDraftValueFor(state: QuestionnaireState, tab: number): string {
|
|
|
100
107
|
const draft = state.customDraftsByTab.get(tab);
|
|
101
108
|
if (draft !== undefined) return draft;
|
|
102
109
|
const answer = state.answers.get(tab);
|
|
103
|
-
|
|
110
|
+
if (answer?.kind !== "custom" && answer?.kind !== "multi") return "";
|
|
111
|
+
return typeof answer.answer === "string" ? answer.answer : "";
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
function setCustomDraft(state: QuestionnaireState, tab: number, value: string): ReadonlyMap<number, string> {
|
|
@@ -170,7 +178,10 @@ const navHandler: Handler<"nav"> = (state, action, ctx) => {
|
|
|
170
178
|
const customDraftsByTab = state.inputMode
|
|
171
179
|
? setCustomDraft(state, state.currentTab, action.inputValue)
|
|
172
180
|
: state.customDraftsByTab;
|
|
173
|
-
|
|
181
|
+
let next: QuestionnaireState = { ...state, optionIndex: action.nextIndex, inputMode, customDraftsByTab };
|
|
182
|
+
if (state.inputMode && !inputMode && ctx.questions[state.currentTab]?.multiSelect) {
|
|
183
|
+
next = { ...next, answers: persistMultiSelectAnswer(next, ctx) };
|
|
184
|
+
}
|
|
174
185
|
if (!inputMode) return { state: next, effects: [] };
|
|
175
186
|
return {
|
|
176
187
|
state: next,
|
|
@@ -195,8 +206,10 @@ const tabSwitchHandler: Handler<"tab_switch"> = (state, action, ctx) => switchTa
|
|
|
195
206
|
|
|
196
207
|
const confirmHandler: Handler<"confirm"> = (state, action, ctx) => {
|
|
197
208
|
let answer = action.answer;
|
|
198
|
-
|
|
199
|
-
|
|
209
|
+
const q = ctx.questions[answer.questionIndex];
|
|
210
|
+
if (answer.kind === "custom" && q?.multiSelect) {
|
|
211
|
+
answer = { ...answer, kind: "multi", selected: selectedLabels(state, q) };
|
|
212
|
+
} else if (answer.kind === "option" && answer.answer) {
|
|
200
213
|
const matched = q?.options.find((o) => o.label === answer.answer);
|
|
201
214
|
if (matched?.preview && matched.preview.length > 0) {
|
|
202
215
|
answer = { ...answer, preview: matched.preview };
|
|
@@ -208,17 +221,14 @@ const confirmHandler: Handler<"confirm"> = (state, action, ctx) => {
|
|
|
208
221
|
}
|
|
209
222
|
const answers = new Map(state.answers);
|
|
210
223
|
answers.set(answer.questionIndex, answer);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const customDraftsByTab =
|
|
216
|
-
answer.kind === "custom" ? withoutCustomDraft(state, answer.questionIndex) : state.customDraftsByTab;
|
|
224
|
+
const hasCustomAnswer = answer.kind === "custom" || (answer.kind === "multi" && answer.answer !== null);
|
|
225
|
+
const customDraftsByTab = hasCustomAnswer
|
|
226
|
+
? withoutCustomDraft(state, answer.questionIndex)
|
|
227
|
+
: state.customDraftsByTab;
|
|
217
228
|
const next: QuestionnaireState = {
|
|
218
229
|
...state,
|
|
219
230
|
answers,
|
|
220
231
|
customDraftsByTab,
|
|
221
|
-
...(isCustomMulti ? { multiSelectChecked: new Set<number>() } : {}),
|
|
222
232
|
};
|
|
223
233
|
if (action.autoAdvanceTab !== undefined) return switchTabResult(next, action.autoAdvanceTab, ctx);
|
|
224
234
|
return doneFor(next, ctx, false);
|
|
@@ -242,13 +252,14 @@ const multiConfirmHandler: Handler<"multi_confirm"> = (state, action, ctx) => {
|
|
|
242
252
|
questionIndex: state.currentTab,
|
|
243
253
|
question: q.question,
|
|
244
254
|
kind: "multi",
|
|
245
|
-
answer:
|
|
255
|
+
answer: action.answer,
|
|
246
256
|
selected: action.selected,
|
|
247
257
|
...(pendingNotes && pendingNotes.length > 0 ? { notes: pendingNotes } : {}),
|
|
248
258
|
});
|
|
249
259
|
const synced: QuestionnaireState = {
|
|
250
260
|
...state,
|
|
251
261
|
answers,
|
|
262
|
+
customDraftsByTab: withoutCustomDraft(state, state.currentTab),
|
|
252
263
|
multiSelectChecked: syncMultiSelectFromAnswers(answers, ctx.questions, state.currentTab),
|
|
253
264
|
};
|
|
254
265
|
if (action.autoAdvanceTab !== undefined) return switchTabResult(synced, action.autoAdvanceTab, ctx);
|
package/tool/format-answer.ts
CHANGED
|
@@ -19,8 +19,11 @@ export type FormatAnswerVariant = "summary" | "envelope";
|
|
|
19
19
|
*/
|
|
20
20
|
export function formatAnswerScalar(a: QuestionAnswer, _variant: FormatAnswerVariant): string {
|
|
21
21
|
switch (a.kind) {
|
|
22
|
-
case "multi":
|
|
23
|
-
|
|
22
|
+
case "multi": {
|
|
23
|
+
const values = [...(a.selected ?? [])];
|
|
24
|
+
if (a.answer && a.answer.length > 0) values.push(a.answer);
|
|
25
|
+
return values.length > 0 ? values.join(", ") : NO_INPUT_PLACEHOLDER;
|
|
26
|
+
}
|
|
24
27
|
case "custom":
|
|
25
28
|
return a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;
|
|
26
29
|
case "option":
|
package/tool/types.ts
CHANGED
|
@@ -100,8 +100,9 @@ export type QuestionParams = Static<typeof QuestionParamsSchema>;
|
|
|
100
100
|
*
|
|
101
101
|
* Variant semantics:
|
|
102
102
|
* - `option`: user picked one of the author-defined options. `answer` is the option's label.
|
|
103
|
-
* - `custom`: user typed free-text
|
|
104
|
-
* - `multi`: user committed multi-select
|
|
103
|
+
* - `custom`: user typed free-text on a single-select question. `answer` is the typed text or null.
|
|
104
|
+
* - `multi`: user committed a multi-select question. `selected` carries chosen labels and `answer`
|
|
105
|
+
* carries optional custom text.
|
|
105
106
|
*/
|
|
106
107
|
export interface QuestionAnswer {
|
|
107
108
|
questionIndex: number;
|
|
@@ -20,6 +20,8 @@ export const MULTI_SUBMIT_LABEL = "Submit";
|
|
|
20
20
|
export interface MultiSelectOtherRowProps {
|
|
21
21
|
/** The "Type something." row is the focused row (optionIndex === options.length). */
|
|
22
22
|
active: boolean;
|
|
23
|
+
/** Non-empty custom text counts as a selected multi-value. */
|
|
24
|
+
checked: boolean;
|
|
23
25
|
/** `state.inputMode` — true once the row has focus and keystrokes append to the buffer. */
|
|
24
26
|
inputMode: boolean;
|
|
25
27
|
/** Live inline-input buffer (read from `runtime.inputBuffer` / `ctx.inputBuffer`). */
|
|
@@ -66,7 +68,7 @@ export class MultiSelectView implements StatefulView<MultiSelectViewProps> {
|
|
|
66
68
|
) {
|
|
67
69
|
this.props = {
|
|
68
70
|
rows: [],
|
|
69
|
-
other: { active: false, inputMode: false, inputBuffer: "", inputCursorOffset: undefined },
|
|
71
|
+
other: { active: false, checked: false, inputMode: false, inputBuffer: "", inputCursorOffset: undefined },
|
|
70
72
|
nextActive: false,
|
|
71
73
|
nextLabel: displayLabel("next"),
|
|
72
74
|
};
|
|
@@ -152,7 +154,7 @@ export class MultiSelectView implements StatefulView<MultiSelectViewProps> {
|
|
|
152
154
|
private renderOtherRow(contentWidth: number, numberWidth: number): string[] {
|
|
153
155
|
const other = this.props.other;
|
|
154
156
|
const pointer = other.active ? this.theme.fg("accent", ACTIVE_POINTER) : INACTIVE_POINTER;
|
|
155
|
-
const box = this.theme.fg("muted", UNCHECKED);
|
|
157
|
+
const box = other.checked ? this.theme.fg("accent", CHECKED) : this.theme.fg("muted", UNCHECKED);
|
|
156
158
|
const number = String(this.question.options.length + 1).padStart(numberWidth, " ");
|
|
157
159
|
const rowPrefix = `${pointer}${number}${NUMBER_SEPARATOR}${box}${BOX_LABEL_GAP}`;
|
|
158
160
|
const continuationPrefix = " ".repeat(visibleWidth(rowPrefix));
|
|
@@ -22,6 +22,21 @@ import type { PreviewLayoutMode } from "./preview-layout-decider.js";
|
|
|
22
22
|
* Re-exported by `preview-pane.ts` for the existing test surface.
|
|
23
23
|
*/
|
|
24
24
|
export const NOTES_AFFORDANCE_TEXT = "Notes: press n to add notes";
|
|
25
|
+
/** Affordance text once the question carries a saved note (#197). */
|
|
26
|
+
export const NOTES_EDIT_AFFORDANCE_TEXT = "Note saved: press n to edit";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Which notes affordance the block shows under the preview: `add` / `edit` (no note yet /
|
|
30
|
+
* a saved note) while the pane is focused with the notes editor closed, `none` otherwise.
|
|
31
|
+
* Decided by the pane from its props; the row itself is kept either way (height-stable).
|
|
32
|
+
*/
|
|
33
|
+
export type NotesAffordance = "add" | "edit" | "none";
|
|
34
|
+
|
|
35
|
+
function affordanceText(affordance: Exclude<NotesAffordance, "none">): string {
|
|
36
|
+
return affordance === "edit"
|
|
37
|
+
? t("preview.notes_edit_affordance", NOTES_EDIT_AFFORDANCE_TEXT)
|
|
38
|
+
: t("preview.notes_affordance", NOTES_AFFORDANCE_TEXT);
|
|
39
|
+
}
|
|
25
40
|
|
|
26
41
|
/** Content row budget for a layout mode: preview cap minus border + affordance overhead. */
|
|
27
42
|
function contentBudgetFor(mode: PreviewLayoutMode): number {
|
|
@@ -93,7 +108,7 @@ export class PreviewBlockRenderer {
|
|
|
93
108
|
|
|
94
109
|
/**
|
|
95
110
|
* Height contribution of the preview block — always equal to `renderBlock(...).length`
|
|
96
|
-
* for the same arguments (the affordance overhead is not gated by `
|
|
111
|
+
* for the same arguments (the affordance overhead is not gated by the `NotesAffordance`).
|
|
97
112
|
* `maxRows` is the row allowance the dialog can give the block; see `fitBlock`.
|
|
98
113
|
*/
|
|
99
114
|
blockHeight(width: number, optionIndex: number, mode: PreviewLayoutMode, maxRows?: number): number {
|
|
@@ -104,18 +119,16 @@ export class PreviewBlockRenderer {
|
|
|
104
119
|
|
|
105
120
|
/**
|
|
106
121
|
* Render the preview block at `width`: bordered box, then (when it fits) a blank separator
|
|
107
|
-
* and the notes-affordance row. `
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* depends on the fit. Under a `maxRows` allowance the box always closes and its bottom border
|
|
122
|
+
* and the notes-affordance row. `affordance` picks the text (`none` blanks it), shown only when
|
|
123
|
+
* the option carries a preview; the row is emitted (empty when gated) whenever the block keeps
|
|
124
|
+
* it, so the row count only depends on the fit. Under a `maxRows` allowance the box always closes and its bottom border
|
|
111
125
|
* counts the lines left out; with no room for a box the block is empty.
|
|
112
126
|
*/
|
|
113
127
|
renderBlock(
|
|
114
128
|
width: number,
|
|
115
129
|
optionIndex: number,
|
|
116
130
|
mode: PreviewLayoutMode,
|
|
117
|
-
|
|
118
|
-
notesVisible: boolean,
|
|
131
|
+
affordance: NotesAffordance,
|
|
119
132
|
maxRows?: number,
|
|
120
133
|
): string[] {
|
|
121
134
|
const maxInnerWidth = innerWidthFor(width);
|
|
@@ -130,10 +143,7 @@ export class PreviewBlockRenderer {
|
|
|
130
143
|
const boxedLines = renderBorderedBox(contentLines, boxWidth, colorFn, hidden);
|
|
131
144
|
if (!fit.affordance) return boxedLines;
|
|
132
145
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
? this.theme.fg("muted", t("preview.notes_affordance", NOTES_AFFORDANCE_TEXT))
|
|
136
|
-
: "";
|
|
137
|
-
return [...boxedLines, "", affordance];
|
|
146
|
+
const text = affordance !== "none" && this.cache.has(optionIndex) ? affordanceText(affordance) : "";
|
|
147
|
+
return [...boxedLines, "", text ? this.theme.fg("muted", text) : ""];
|
|
138
148
|
}
|
|
139
149
|
}
|
|
@@ -4,7 +4,7 @@ import type { QuestionData } from "../../../tool/types.js";
|
|
|
4
4
|
import { windowLines } from "../../scroll-window.js";
|
|
5
5
|
import type { StatefulView } from "../../stateful-view.js";
|
|
6
6
|
import type { OptionListView } from "../option-list-view.js";
|
|
7
|
-
import type { PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
7
|
+
import type { NotesAffordance, PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
8
8
|
import {
|
|
9
9
|
bodyWidths,
|
|
10
10
|
columnWidths,
|
|
@@ -24,7 +24,7 @@ export {
|
|
|
24
24
|
NO_PREVIEW_TEXT,
|
|
25
25
|
NOTES_AFFORDANCE_OVERHEAD,
|
|
26
26
|
} from "./markdown-content-cache.js";
|
|
27
|
-
export { NOTES_AFFORDANCE_TEXT, PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
27
|
+
export { NOTES_AFFORDANCE_TEXT, NOTES_EDIT_AFFORDANCE_TEXT, PreviewBlockRenderer } from "./preview-block-renderer.js";
|
|
28
28
|
export {
|
|
29
29
|
BORDER_HORIZONTAL_OVERHEAD,
|
|
30
30
|
BORDER_INNER_PADDING_HORIZONTAL,
|
|
@@ -51,6 +51,8 @@ export {
|
|
|
51
51
|
*/
|
|
52
52
|
export interface PreviewPaneProps {
|
|
53
53
|
notesVisible: boolean;
|
|
54
|
+
/** The question carries a saved note — the affordance offers to edit it rather than add one (#197). */
|
|
55
|
+
hasNote: boolean;
|
|
54
56
|
selectedIndex: number;
|
|
55
57
|
focused: boolean;
|
|
56
58
|
/**
|
|
@@ -111,7 +113,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
111
113
|
this.optionListView = config.optionListView;
|
|
112
114
|
this.previewBlock = config.previewBlock;
|
|
113
115
|
this.theme = config.theme;
|
|
114
|
-
this.props = { notesVisible: false, selectedIndex: 0, focused: false, inputMode: false };
|
|
116
|
+
this.props = { notesVisible: false, hasNote: false, selectedIndex: 0, focused: false, inputMode: false };
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
setGlobalLeftWidth(getter: (paneWidth: number) => number): void {
|
|
@@ -127,6 +129,13 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
/** Render-time geometry from `DialogView` (not canonical state, so not a prop). */
|
|
132
|
+
/** The notes affordance under the preview: shown while focused with the notes editor closed. */
|
|
133
|
+
private notesAffordance(): NotesAffordance {
|
|
134
|
+
const { focused, notesVisible, hasNote } = this.props;
|
|
135
|
+
if (!focused || notesVisible) return "none";
|
|
136
|
+
return hasNote ? "edit" : "add";
|
|
137
|
+
}
|
|
138
|
+
|
|
130
139
|
setRowAllowance(rows: number | undefined): void {
|
|
131
140
|
this.rowAllowance = rows;
|
|
132
141
|
}
|
|
@@ -171,7 +180,8 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
171
180
|
width: number,
|
|
172
181
|
mode: PreviewLayoutMode,
|
|
173
182
|
): { lines: string[]; focus: [number, number] | undefined } {
|
|
174
|
-
const { selectedIndex
|
|
183
|
+
const { selectedIndex } = this.props;
|
|
184
|
+
const affordance = this.notesAffordance();
|
|
175
185
|
const options = this.optionListView.render(width);
|
|
176
186
|
const focus = this.optionListView.focusedItemRowRange(width);
|
|
177
187
|
const gap = Array<string>(STACKED_GAP_ROWS).fill("");
|
|
@@ -179,11 +189,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
179
189
|
const fullBlock = this.previewBlock.blockHeight(width, selectedIndex, mode);
|
|
180
190
|
if (allowance === undefined || options.length + STACKED_GAP_ROWS + fullBlock <= allowance) {
|
|
181
191
|
return {
|
|
182
|
-
lines: [
|
|
183
|
-
...options,
|
|
184
|
-
...gap,
|
|
185
|
-
...this.previewBlock.renderBlock(width, selectedIndex, mode, focused, notesVisible),
|
|
186
|
-
],
|
|
192
|
+
lines: [...options, ...gap, ...this.previewBlock.renderBlock(width, selectedIndex, mode, affordance)],
|
|
187
193
|
focus,
|
|
188
194
|
};
|
|
189
195
|
}
|
|
@@ -194,7 +200,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
194
200
|
Math.min(fullBlock, allowance - STACKED_GAP_ROWS - Math.min(options.length, optionsFloor));
|
|
195
201
|
const roomy = previewRowsWith(focusRows + 2);
|
|
196
202
|
const previewRows = roomy >= MIN_BOX_ROWS ? roomy : previewRowsWith(focusRows);
|
|
197
|
-
const block = this.previewBlock.renderBlock(width, selectedIndex, mode,
|
|
203
|
+
const block = this.previewBlock.renderBlock(width, selectedIndex, mode, affordance, previewRows);
|
|
198
204
|
const optionRows = allowance - (block.length > 0 ? STACKED_GAP_ROWS + block.length : 0);
|
|
199
205
|
const windowed = windowLines(options, Math.max(1, optionRows), focus, this.theme);
|
|
200
206
|
return {
|
|
@@ -296,8 +302,7 @@ export class PreviewPane implements StatefulView<PreviewPaneProps>, Component {
|
|
|
296
302
|
inner,
|
|
297
303
|
this.props.selectedIndex,
|
|
298
304
|
mode,
|
|
299
|
-
this.
|
|
300
|
-
this.props.notesVisible,
|
|
305
|
+
this.notesAffordance(),
|
|
301
306
|
maxRows,
|
|
302
307
|
);
|
|
303
308
|
const boxWidth = Math.max(1, visibleWidth(contentLines[0] ?? ""));
|
package/view/dialog-builder.ts
CHANGED
|
@@ -159,12 +159,17 @@ export class DialogView implements StatefulView<DialogProps> {
|
|
|
159
159
|
const natural = this.buildContainerFromStrategy(strategy, headingRowCache).render(width);
|
|
160
160
|
|
|
161
161
|
// Residual spacer: equalizes total height across tabs (only needed when no overflow).
|
|
162
|
+
// Resting mid rows (a question's saved-note row, #197) come out of the spacer's slack,
|
|
163
|
+
// so a tab with a note keeps the shared height when the body leaves room. The open
|
|
164
|
+
// notes editor deliberately grows the dialog instead, so it is not absorbed.
|
|
165
|
+
const restingMidRows = state.notesVisible ? 0 : this.rowsAroundBody(strategy, width) - 1;
|
|
162
166
|
const spacerRows = Math.max(
|
|
163
167
|
0,
|
|
164
168
|
this.config.getBodyHeight(width) +
|
|
165
169
|
this.maxFooterRowCount -
|
|
166
170
|
strategy.bodyHeight(width, state) -
|
|
167
|
-
strategy.footerRowCount
|
|
171
|
+
strategy.footerRowCount -
|
|
172
|
+
restingMidRows,
|
|
168
173
|
);
|
|
169
174
|
|
|
170
175
|
// The spacer is padding for a stable cross-tab footprint, not content: when only the
|
|
@@ -2,6 +2,7 @@ import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { type Component, Container, type Editor, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.js";
|
|
4
4
|
import { t } from "../state/i18n-bridge.js";
|
|
5
|
+
import { selectSavedNote } from "../state/selectors/derivations.js";
|
|
5
6
|
import { formatAnswerScalar } from "../tool/format-answer.js";
|
|
6
7
|
import type { QuestionData } from "../tool/types.js";
|
|
7
8
|
import type { PreviewPane, PreviewPaneProps } from "./components/preview/preview-pane.js";
|
|
@@ -28,6 +29,8 @@ const NOTES_HEADER = "Notes:";
|
|
|
28
29
|
const GLOBAL_NOTES_HEADER = "Global note:";
|
|
29
30
|
const REVIEW_GLOBAL_HINT = "n to add a note";
|
|
30
31
|
const REVIEW_NOTE_LABEL = "Note";
|
|
32
|
+
/** Label for a question's saved note — the question tab's resting row and the review entry (#197). */
|
|
33
|
+
const SAVED_NOTE_LABEL = "Note for this answer:";
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Single-row, width-clipped chrome cell. The footer row count is invariant
|
|
@@ -128,12 +131,22 @@ export class QuestionTabStrategy implements TabContentStrategy {
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
midRows(state: DialogState): Component[] {
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
if (state.notesVisible) {
|
|
135
|
+
return [
|
|
136
|
+
new Text(this.config.theme.fg("muted", t("notes.header", NOTES_HEADER)), 1, 0),
|
|
137
|
+
this.config.notesInput,
|
|
138
|
+
new Spacer(1),
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
// A saved note stays visible once its editor closes (#197): one clipped row, so a long
|
|
142
|
+
// or multi-line note cannot crowd the options — `n` reopens it in full. Mid rows are
|
|
143
|
+
// subtracted from the body allowance (`DialogView.rowsAroundBody`), so the row is
|
|
144
|
+
// height-safe.
|
|
145
|
+
const note = selectSavedNote(state.notesByTab, state.answers, state.currentTab);
|
|
146
|
+
if (note === undefined) return [];
|
|
147
|
+
const [firstLine = "", ...rest] = note.split("\n");
|
|
148
|
+
const text = `${t("notes.saved_label", SAVED_NOTE_LABEL)} ${firstLine}${rest.length > 0 ? " …" : ""}`;
|
|
149
|
+
return [new OneLineClippedText(this.config.theme.fg("dim", text), 1)];
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
footerRows(state: DialogState): Component[] {
|
|
@@ -193,7 +206,13 @@ export class SubmitTabStrategy implements TabContentStrategy {
|
|
|
193
206
|
new Text(` ${this.config.theme.fg("muted", "→")} ${this.config.theme.fg("text", answerText)}`, 1, 0),
|
|
194
207
|
);
|
|
195
208
|
if (a.notes && a.notes.length > 0) {
|
|
196
|
-
c.addChild(
|
|
209
|
+
c.addChild(
|
|
210
|
+
new Text(
|
|
211
|
+
this.config.theme.fg("dim", ` ${t("notes.saved_label", SAVED_NOTE_LABEL)} ${a.notes}`),
|
|
212
|
+
1,
|
|
213
|
+
0,
|
|
214
|
+
),
|
|
215
|
+
);
|
|
197
216
|
}
|
|
198
217
|
}
|
|
199
218
|
// Committed global note (#182) as a review entry — pressing `n` gets visible
|