fix: issue where plaintext editor autofocus would interfere with sign in form

This commit is contained in:
Mo
2022-11-25 06:41:40 -06:00
parent 21611d9b45
commit a6efc5336b
2 changed files with 15 additions and 13 deletions

View File

@@ -231,16 +231,8 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
}
}
setPlainEditorRef = (ref: PlainEditorInterface | undefined) => {
setPlainEditorRef = (ref: PlainEditorInterface | null) => {
this.plainEditorRef = ref || undefined
if (!this.plainEditorRef) {
return
}
if (this.controller.isTemplateNote && this.controller.templateNoteOptions?.autofocusBehavior === 'editor') {
this.plainEditorRef.focus()
}
}
override componentDidUpdate(_prevProps: NoteViewProps, prevState: State): void {
@@ -956,7 +948,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
<PlainEditor
application={this.application}
spellcheck={this.state.spellcheck}
ref={(ref) => this.setPlainEditorRef(ref || undefined)}
ref={this.setPlainEditorRef}
controller={this.controller}
locked={this.state.noteLocked}
onFocus={this.onPlainFocus}

View File

@@ -132,9 +132,15 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
useEffect(() => {
if (controller.isTemplateNote && controller.templateNoteOptions?.autofocusBehavior === 'editor') {
setTimeout(() => {
focusEditor()
})
focusEditor()
}
}, [controller, focusEditor])
useEffect(() => {
const shouldFocus = controller.isTemplateNote && controller.templateNoteOptions?.autofocusBehavior === 'editor'
if (shouldFocus) {
focusEditor()
}
}, [controller, focusEditor])
@@ -155,6 +161,10 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
}, [reloadPreferences, application])
useEffect(() => {
if (previousSpellcheck === undefined) {
return
}
if (spellcheck !== previousSpellcheck) {
setTextareaUnloading(true)
setTimeout(() => {