| 43 | > {} |
| 44 | |
| 45 | export class AnnotationCreate extends React.Component<Props, State> |
| 46 | implements FocusableComponent { |
| 47 | static ALT_KEY = getKeyName({ key: 'alt' }) |
| 48 | static MOD_KEY = getKeyName({ key: 'mod' }) |
| 49 | private textAreaRef = React.createRef<HTMLTextAreaElement>() |
| 50 | private markdownPreviewRef = React.createRef< |
| 51 | MarkdownPreviewAnnotationInsertMenu |
| 52 | >() |
| 53 | |
| 54 | state: State = { |
| 55 | isTagPickerShown: false, |
| 56 | } |
| 57 | |
| 58 | componentDidMount() { |
| 59 | if (this.props.autoFocus) { |
| 60 | this.focus() |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | focus() { |
| 65 | const inputLen = this.props.comment.length |
| 66 | this.textAreaRef.current.focus() |
| 67 | this.textAreaRef.current.setSelectionRange(inputLen, inputLen) |
| 68 | } |
| 69 | |
| 70 | handleClickOutside() { |
| 71 | if (this.props.hide && !this.props.comment.length) { |
| 72 | this.props.hide() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | private hideTagPicker = () => this.setState({ isTagPickerShown: false }) |
| 77 | private handleCancel = () => this.props.onCancel() |
| 78 | private handleSave = async ( |
| 79 | shouldShare: boolean, |
| 80 | isProtected?: boolean, |
| 81 | ) => { |
| 82 | const saveP = this.props.onSave(shouldShare, isProtected) |
| 83 | |
| 84 | if ( |
| 85 | this.markdownPreviewRef?.current?.markdownPreviewRef.current?.state |
| 86 | .showPreview |
| 87 | ) { |
| 88 | this.markdownPreviewRef.current.markdownPreviewRef.current.togglePreview() |
| 89 | } |
| 90 | |
| 91 | await saveP |
| 92 | } |
| 93 | |
| 94 | private handleInputKeyDown: React.KeyboardEventHandler = (e) => { |
| 95 | // Allow escape keydown to bubble up to close the sidebar only if no input state |
| 96 | if (e.key === 'Escape') { |
| 97 | if (this.props.comment.length) { |
| 98 | e.stopPropagation() |
| 99 | } |
| 100 | this.props.onCancel() |
| 101 | return |
| 102 | } |
nothing calls this directly
no test coverage detected