@@ -202,7 +202,7 @@ export function Prompt(props: PromptProps) {
202202 category : "Session" ,
203203 onSelect : ( dialog ) => {
204204 if ( autocomplete . visible ) return
205- if ( ! input . focused ) return
205+ if ( ! input ? .focused ) return
206206 // TODO: this should be its own command
207207 if ( store . mode === "shell" ) {
208208 setStore ( "mode" , "normal" )
@@ -446,6 +446,7 @@ export function Prompt(props: PromptProps) {
446446 dialog . replace ( ( ) => (
447447 < DialogStash
448448 onSelect = { ( entry ) => {
449+ if ( ! input ) return
449450 input . setText ( entry . input )
450451 setStore ( "prompt" , { input : entry . input , parts : entry . parts } )
451452 restoreExtmarksFromParts ( entry . parts )
@@ -806,8 +807,8 @@ export function Prompt(props: PromptProps) {
806807 // If no image, let the default paste behavior continue
807808 }
808809 if ( keybind . match ( "input_clear" , e ) && store . prompt . input !== "" ) {
809- input . clear ( )
810- input . extmarks . clear ( )
810+ input ? .clear ( )
811+ input ? .extmarks . clear ( )
811812 setStore ( "prompt" , {
812813 input : "" ,
813814 parts : [ ] ,
@@ -823,13 +824,13 @@ export function Prompt(props: PromptProps) {
823824 return
824825 }
825826 }
826- if ( e . name === "!" && input . visualCursor . offset === 0 ) {
827+ if ( e . name === "!" && input ? .visualCursor . offset === 0 ) {
827828 setStore ( "mode" , "shell" )
828829 e . preventDefault ( )
829830 return
830831 }
831832 if ( store . mode === "shell" ) {
832- if ( ( e . name === "backspace" && input . visualCursor . offset === 0 ) || e . name === "escape" ) {
833+ if ( ( e . name === "backspace" && input ? .visualCursor . offset === 0 ) || e . name === "escape" ) {
833834 setStore ( "mode" , "normal" )
834835 e . preventDefault ( )
835836 return
@@ -838,9 +839,10 @@ export function Prompt(props: PromptProps) {
838839 if ( store . mode === "normal" ) autocomplete . onKeyDown ( e )
839840 if ( ! autocomplete . visible ) {
840841 if (
841- ( keybind . match ( "history_previous" , e ) && input . cursorOffset === 0 ) ||
842- ( keybind . match ( "history_next" , e ) && input . cursorOffset === input . plainText . length )
842+ ( keybind . match ( "history_previous" , e ) && input ? .cursorOffset === 0 ) ||
843+ ( keybind . match ( "history_next" , e ) && input ? .cursorOffset === input ? .plainText . length )
843844 ) {
845+ if ( ! input ) return
844846 const direction = keybind . match ( "history_previous" , e ) ? - 1 : 1
845847 const item = history . move ( direction , input . plainText )
846848
@@ -856,8 +858,13 @@ export function Prompt(props: PromptProps) {
856858 return
857859 }
858860
859- if ( keybind . match ( "history_previous" , e ) && input . visualCursor . visualRow === 0 ) input . cursorOffset = 0
860- if ( keybind . match ( "history_next" , e ) && input . visualCursor . visualRow === input . height - 1 )
861+ if ( keybind . match ( "history_previous" , e ) && input ?. visualCursor . visualRow === 0 && input )
862+ input . cursorOffset = 0
863+ if (
864+ keybind . match ( "history_next" , e ) &&
865+ input ?. visualCursor . visualRow === ( input ?. height ?? 0 ) - 1 &&
866+ input
867+ )
861868 input . cursorOffset = input . plainText . length
862869 }
863870 } }
0 commit comments