diff options
Diffstat (limited to 'src/client/views/nodes/EquationBox.tsx')
-rw-r--r-- | src/client/views/nodes/EquationBox.tsx | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/client/views/nodes/EquationBox.tsx b/src/client/views/nodes/EquationBox.tsx index c279341cc..163c5a9ed 100644 --- a/src/client/views/nodes/EquationBox.tsx +++ b/src/client/views/nodes/EquationBox.tsx @@ -21,6 +21,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() { public static SelectOnLoad: string = ''; _ref: React.RefObject<EquationEditor> = React.createRef(); componentDidMount() { + this.props.setContentView?.(this); if (EquationBox.SelectOnLoad === this.rootDoc[Id] && (!LightboxView.LightboxDoc || LightboxView.IsLightboxDocView(this.props.docViewPath()))) { this.props.select(false); @@ -78,14 +79,13 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() { if (e.key === 'Backspace' && !this.dataDoc.text) this.props.removeDocument?.(this.rootDoc); }; @undoBatch - onChange = (str: string) => { - this.dataDoc.text = str; + onChange = (str: string) => (this.dataDoc.text = str); + + updateSize = () => { const style = this._ref.current && getComputedStyle(this._ref.current.element.current); - if (style) { - const _height = Number(style.height.replace('px', '')); - const _width = Number(style.width.replace('px', '')); - this.layoutDoc._width = Math.max(35, _width); - this.layoutDoc._height = Math.max(25, _height); + if (style?.width.endsWith('px') && style?.height.endsWith('px')) { + this.layoutDoc._width = Math.max(35, Number(style.width.replace('px', ''))); + this.layoutDoc._height = Math.max(25, Number(style.height.replace('px', ''))); } }; render() { @@ -93,16 +93,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() { const scale = (this.props.NativeDimScaling?.() || 1) * NumCast(this.layoutDoc._viewScale, 1); return ( <div - ref={r => { - r instanceof HTMLDivElement && - new ResizeObserver( - action((entries: any) => { - if (entries[0].contentBoxSize[0].inlineSize) { - this.rootDoc._width = entries[0].contentBoxSize[0].inlineSize; - } - }) - ).observe(r); - }} + ref={r => this.updateSize()} className="equationBox-cont" onPointerDown={e => !e.ctrlKey && e.stopPropagation()} style={{ @@ -110,6 +101,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() { width: 'fit-content', // `${100 / scale}%`, height: `${100 / scale}%`, pointerEvents: !this.props.isSelected() ? 'none' : undefined, + fontSize: StrCast(this.rootDoc._fontSize), }} onKeyDown={e => e.stopPropagation()}> <EquationEditor ref={this._ref} value={this.dataDoc.text || 'x'} spaceBehavesLikeTab={true} onChange={this.onChange} autoCommands="pi theta sqrt sum prod alpha beta gamma rho" autoOperatorNames="sin cos tan" /> |