diff options
author | bobzel <zzzman@gmail.com> | 2021-03-30 21:48:03 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-03-30 21:48:03 -0400 |
commit | 3172a475102691c720b7e7d0b696814237855914 (patch) | |
tree | 6c579dcc136bbd19a27c46f77bc2311839d3dfc0 /src/client/views/nodes/formattedText/FormattedTextBox.tsx | |
parent | 8b92374feed3152cf4eaf4e82735897565d8b2dc (diff) |
added setFocus component view method
Diffstat (limited to 'src/client/views/nodes/formattedText/FormattedTextBox.tsx')
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index f57a8d91e..26e78cfbf 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -145,7 +145,6 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp }; } - public static FocusedBox: FormattedTextBox | undefined; public static PasteOnLoad: ClipboardEvent | undefined; public static SelectOnLoad = ""; public static DontSelectInitialText = false; // whether initial text should be selected or not @@ -1224,18 +1223,14 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp e.stopPropagation(); } } + setFocus = () => { + const pos = this._editorView?.state.selection.$from.pos || 1; + (this.ProseRef?.children?.[0] as any).focus(); + setTimeout(() => this._editorView?.dispatch(this._editorView?.state.tr.setSelection(TextSelection.create(this._editorView.state.doc, pos)))); + } @action onFocused = (e: React.FocusEvent): void => { - FormattedTextBox.FocusedBox = this; //applyDevTools.applyDevTools(this._editorView); - - // see if we need to preserve the insertion point - const prosediv = this.ProseRef?.children?.[0] as any; - const keeplocation = prosediv?.keeplocation; - prosediv && (prosediv.keeplocation = undefined); - const pos = this._editorView?.state.selection.$from.pos || 1; - keeplocation && setTimeout(() => this._editorView?.dispatch(this._editorView?.state.tr.setSelection(TextSelection.create(this._editorView.state.doc, pos)))); - this._editorView && RichTextMenu.Instance?.updateMenu(this._editorView, undefined, this.props); } |