11import { TextareaRenderable , TextAttributes } from "@opentui/core"
22import { useTheme } from "../context/theme"
33import { useDialog , type DialogContext } from "./dialog"
4- import { Show , createEffect , createSignal , onMount , type JSX } from "solid-js"
4+ import { Show , createEffect , onMount , type JSX } from "solid-js"
55import { Spinner } from "../component/spinner"
6- import { useTuiConfig } from "../context/tui-config"
7- import { useBindings , useCommandShortcut } from "../keymap"
86
97export type DialogPromptProps = {
108 title : string
@@ -20,32 +18,8 @@ export type DialogPromptProps = {
2018export function DialogPrompt ( props : DialogPromptProps ) {
2119 const dialog = useDialog ( )
2220 const { theme } = useTheme ( )
23- const tuiConfig = useTuiConfig ( )
24- const submitShortcut = useCommandShortcut ( "dialog.prompt.submit" )
25- const [ textareaTarget , setTextareaTarget ] = createSignal < TextareaRenderable > ( )
2621 let textarea : TextareaRenderable
2722
28- function confirm ( ) {
29- if ( props . busy ) return
30- props . onConfirm ?.( textarea . plainText )
31- }
32-
33- useBindings ( ( ) => ( {
34- target : textareaTarget ,
35- enabled : textareaTarget ( ) !== undefined && ! props . busy ,
36- // Dialog form semantics must win over the global managed textarea input layer.
37- priority : 1 ,
38- commands : [
39- {
40- name : "dialog.prompt.submit" ,
41- title : "Submit dialog prompt" ,
42- category : "Dialog" ,
43- run : confirm ,
44- } ,
45- ] ,
46- bindings : tuiConfig . keybinds . gather ( "dialog.prompt" , [ "dialog.prompt.submit" ] ) ,
47- } ) )
48-
4923 onMount ( ( ) => {
5024 dialog . setSize ( "medium" )
5125 setTimeout ( ( ) => {
@@ -85,10 +59,13 @@ export function DialogPrompt(props: DialogPromptProps) {
8559 < box gap = { 1 } >
8660 { props . description }
8761 < textarea
62+ onSubmit = { ( ) => {
63+ if ( props . busy ) return
64+ props . onConfirm ?.( textarea . plainText )
65+ } }
8866 height = { 3 }
8967 ref = { ( val : TextareaRenderable ) => {
9068 textarea = val
91- setTextareaTarget ( val )
9269 } }
9370 initialValue = { props . value }
9471 placeholder = { props . placeholder ?? "Enter text" }
@@ -103,11 +80,9 @@ export function DialogPrompt(props: DialogPromptProps) {
10380 </ box >
10481 < box paddingBottom = { 1 } gap = { 1 } flexDirection = "row" >
10582 < Show when = { ! props . busy } fallback = { < text fg = { theme . textMuted } > processing...</ text > } >
106- < Show when = { submitShortcut ( ) } >
107- < text fg = { theme . text } >
108- { submitShortcut ( ) } < span style = { { fg : theme . textMuted } } > submit</ span >
109- </ text >
110- </ Show >
83+ < text fg = { theme . text } >
84+ enter < span style = { { fg : theme . textMuted } } > submit</ span >
85+ </ text >
11186 </ Show >
11287 </ box >
11388 </ box >
0 commit comments