From 576f67c5a06efed2124ac96aabbbf6a751746135 Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 31 Mar 2023 12:34:13 -0700 Subject: [PATCH] fix initial size --- src/simplerenderer.tsx | 2 +- src/webshare-elems.tsx | 40 +++++++--------------------------------- src/webshare-model.ts | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/simplerenderer.tsx b/src/simplerenderer.tsx index 864012d6..05dfed28 100644 --- a/src/simplerenderer.tsx +++ b/src/simplerenderer.tsx @@ -103,7 +103,7 @@ class SimpleBlobRenderer extends React.Component<{rendererContainer : RendererCo constructor(props : any) { super(props); - let {rendererContainer, cmdId, initParams} = this.props; + let {rendererContainer, cmdId, plugin, initParams} = this.props; this.model = new SimpleBlobRendererModel(); this.model.initialize(initParams); rendererContainer.registerRenderer(cmdId, this.model); diff --git a/src/webshare-elems.tsx b/src/webshare-elems.tsx index 1a57b404..5856e8be 100644 --- a/src/webshare-elems.tsx +++ b/src/webshare-elems.tsx @@ -125,7 +125,6 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd, cmdTextRef : React.RefObject = React.createRef(); copiedIndicator : OV = mobx.observable.box(false, {name: "copiedIndicator"}); lastHeight : number; - lastScreenSize : T.WindowSize; componentDidMount() : void { this.checkCmdText(); @@ -243,9 +242,6 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd, if (elem != null) { curHeight = elem.offsetHeight; curWidth = elem.offsetWidth; - if (curHeight != 0 && curWidth != 0) { - this.lastScreenSize = {height: curHeight, width: curWidth}; - } } if (this.lastHeight == curHeight) { return; @@ -304,35 +300,11 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd, }, 600); } - getMaxContentSize() : T.WindowSize { - if (this.lastScreenSize == null) { - let width = termWidthFromCols(80, WebShareModel.getTermFontSize()); - let height = termHeightFromRows(25, WebShareModel.getTermFontSize()); - return {width, height}; - } - let winSize = this.lastScreenSize; - let width = util.boundInt(winSize.width-50, 100, 5000); - let height = util.boundInt(winSize.height-100, 100, 5000); - return {width, height}; - } - - getIdealContentSize() : T.WindowSize { - if (this.lastScreenSize == null) { - let width = termWidthFromCols(80, WebShareModel.getTermFontSize()); - let height = termHeightFromRows(25, WebShareModel.getTermFontSize()); - return {width, height}; - } - let winSize = this.lastScreenSize; - let width = util.boundInt(Math.ceil((winSize.width-50)*0.7), 100, 5000); - let height = util.boundInt(Math.ceil((winSize.height-100)*0.5), 100, 5000); - return {width, height}; - } - getRendererOpts(cmd : T.WebCmd) : T.RendererOpts { return { - maxSize: this.getMaxContentSize(), - idealSize: this.getIdealContentSize(), - termOpts: cmd.termopts, + maxSize: WebShareModel.getMaxContentSize(), + idealSize: WebShareModel.getIdealContentSize(), + termOpts: mobx.toJS(cmd.termopts), termFontSize: WebShareModel.getTermFontSize(), }; } @@ -582,7 +554,7 @@ class WebLineView extends React.Component<{line : T.WebLine, cmd : T.WebCmd, top class WebScreenView extends React.Component<{}, {}> { viewRef : React.RefObject = React.createRef(); width : OV = mobx.observable.box(0, {name: "WebScreenView-width"}); - handleResize_debounced : (entries : any) => void; + handleResize_debounced : () => void; rszObs : ResizeObserver; constructor(props : any) { @@ -599,18 +571,20 @@ class WebScreenView extends React.Component<{}, {}> { if (width > 0) { mobx.action(() => { this.width.set(width); + this.handleResize(); })(); } } } - handleResize(entries : any) : void { + handleResize() : void { let viewElem = this.viewRef.current; if (viewElem == null) { return; } let width = viewElem.offsetWidth; let height = viewElem.offsetHeight; + WebShareModel.setLastScreenSize({width, height}); if (width != this.width.get()) { WebShareModel.resizeWindow({width: width, height: height}); mobx.action(() => { diff --git a/src/webshare-model.ts b/src/webshare-model.ts index 3e5ebb03..51f9261a 100644 --- a/src/webshare-model.ts +++ b/src/webshare-model.ts @@ -5,6 +5,7 @@ import {handleJsonFetchResponse, isModKeyPress, base64ToArray} from "./util"; import * as T from "./types"; import {TermWrap} from "./term"; import * as lineutil from "./lineutil"; +import * as util from "./util"; import {windowWidthToCols, windowHeightToRows, termWidthFromCols, termHeightFromRows} from "./textmeasure"; import {WebShareWSControl} from "./webshare-ws"; @@ -37,6 +38,7 @@ class WebShareModelClass { anchor : {anchorLine : number, anchorOffset : number} = {anchorLine: 0, anchorOffset: 0}; selectedLine : OV = mobx.observable.box(0, {name: "selectedLine"}); syncSelectedLine : OV = mobx.observable.box(true, {name: "syncSelectedLine"}); + lastScreenSize : T.WindowSize = null; constructor() { let urlParams = new URLSearchParams(window.location.search); @@ -65,6 +67,37 @@ class WebShareModelClass { })(); } + setLastScreenSize(winSize : T.WindowSize) { + if (winSize == null || winSize.height == 0 || winSize.width == 0) { + return; + } + this.lastScreenSize = winSize; + } + + getMaxContentSize() : T.WindowSize { + if (this.lastScreenSize == null) { + let width = termWidthFromCols(80, WebShareModel.getTermFontSize()); + let height = termHeightFromRows(25, WebShareModel.getTermFontSize()); + return {width, height}; + } + let winSize = this.lastScreenSize; + let width = util.boundInt(winSize.width-50, 100, 5000); + let height = util.boundInt(winSize.height-100, 100, 5000); + return {width, height}; + } + + getIdealContentSize() : T.WindowSize { + if (this.lastScreenSize == null) { + let width = termWidthFromCols(80, WebShareModel.getTermFontSize()); + let height = termHeightFromRows(25, WebShareModel.getTermFontSize()); + return {width, height}; + } + let winSize = this.lastScreenSize; + let width = util.boundInt(Math.ceil((winSize.width-50)*0.7), 100, 5000); + let height = util.boundInt(Math.ceil((winSize.height-100)*0.5), 100, 5000); + return {width, height}; + } + getSelectedLine() : number { return this.selectedLine.get(); }