@@ -4,7 +4,6 @@ import "./TextInput.css";
4
4
import { parseSpark } from "../../../scripts/utils/stringUtils" ;
5
5
import { isUserSelectingTag } from "./TagList/TagList" ;
6
6
import { isUserSelectingExtension } from "./SparkExtensionList/SparkExtensionList" ;
7
- import { useEffect } from "react" ;
8
7
9
8
export type TextInputProps = {
10
9
onSubmit ?: ( plainText : string , html : string ) => void ;
@@ -16,10 +15,9 @@ export type TextInputProps = {
16
15
style ?: keyof typeof styleMap ;
17
16
placeholder ?: string ;
18
17
content ?: string ;
18
+ onEscape ?: ( ) => void ;
19
19
} ;
20
20
21
- let editor : Editor | null = null ;
22
-
23
21
const styleMap = {
24
22
spark : "p-4 min-h-full block w-full bg-white border border-blue-300 rounded-lg text-sm focus:border-blue-500 focus:ring-blue-500 disabled:opacity-50 disabled:pointer-events-none dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 dark:placeholder-neutral-500 dark:focus:ring-neutral-600" ,
25
23
search : "px-4 py-2 block w-full bg-transparent hover:bg-white focus:bg-white border-b border-b-stone-200 rounded" ,
@@ -38,8 +36,9 @@ export const TextInput = (props: TextInputProps) => {
38
36
placeholder,
39
37
enableTags,
40
38
enableExtension,
39
+ onEscape,
41
40
} = props ;
42
- editor = useEditor ( {
41
+ const editor = useEditor ( {
43
42
content,
44
43
extensions : getExtensions ( {
45
44
parentWindow : parentWindow ?? window ,
@@ -58,13 +57,16 @@ export const TextInput = (props: TextInputProps) => {
58
57
if ( ! onSubmit ) {
59
58
return false ;
60
59
}
61
- if ( event . key !== "Enter" || event . shiftKey ) {
62
- return false ;
63
- }
64
60
if ( isUserSelectingTag || isUserSelectingExtension ) {
65
61
// user currently has the selection open and might have pressed enter to select an item
66
62
return false ;
67
63
}
64
+ if ( event . key !== "Enter" || event . shiftKey ) {
65
+ if ( event . key === "Escape" ) {
66
+ onEscape ?.( ) ;
67
+ }
68
+ return false ;
69
+ }
68
70
const html = editor ?. getHTML ( ) . trim ( ) ?? "" ;
69
71
const plainText = editor ?. getText ( ) . trim ( ) ?? "" ;
70
72
if ( html === "" ) {
0 commit comments