diff options
author | bobzel <zzzman@gmail.com> | 2021-02-28 01:51:29 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-02-28 01:51:29 -0500 |
commit | 8f4d9fd82eb798e86508978f77fcb57e4c3b8651 (patch) | |
tree | 4493f741edff9240befb4525a9b3ffbf0eca78fa /src | |
parent | 7902b1021b89e45bd595e4a9588db11dccbf9831 (diff) |
got rid of delayAutoHeight by updating dragHeights in documentDecorations.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/DocumentDecorations.tsx | 20 | ||||
-rw-r--r-- | src/client/views/MainView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 17 |
4 files changed, 17 insertions, 26 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index f41238228..92f5b79bd 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -292,10 +292,7 @@ export class DocumentDecorations extends React.Component<{ boundsLeft: number, b this._rotateUndo = undefined; } - - - _initialAutoHeight = false; - _dragHeights = new Map<Doc, number>(); + _dragHeights = new Map<Doc, { start: number, lowest: number }>(); @action onPointerDown = (e: React.PointerEvent): void => { @@ -323,12 +320,9 @@ export class DocumentDecorations extends React.Component<{ boundsLeft: number, b } this._snapX = e.pageX; this._snapY = e.pageY; - this._initialAutoHeight = true; DragManager.docsBeingDragged = SelectionManager.Views().map(dv => dv.rootDoc); - SelectionManager.Views().map(dv => { - this._dragHeights.set(dv.layoutDoc, NumCast(dv.layoutDoc._height)); - dv.layoutDoc._delayAutoHeight = dv.layoutDoc._height; - }); + SelectionManager.Views().map(dv => + this._dragHeights.set(dv.layoutDoc, { start: NumCast(dv.layoutDoc._height), lowest: NumCast(dv.layoutDoc._height) })); } onPointerMove = (e: PointerEvent, down: number[], move: number[]): boolean => { @@ -471,9 +465,11 @@ export class DocumentDecorations extends React.Component<{ boundsLeft: number, b } else { dW && (doc._width = actualdW); dH && (doc._height = actualdH); - dH && this._initialAutoHeight && (doc._autoHeight = this._initialAutoHeight = false); + dH && (doc._autoHeight = false); } } + const val = this._dragHeights.get(docView.layoutDoc); + if (val) this._dragHeights.set(docView.layoutDoc, { start: val.start, lowest: Math.min(val.lowest, NumCast(docView.layoutDoc._height)) }); })); return false; } @@ -481,12 +477,12 @@ export class DocumentDecorations extends React.Component<{ boundsLeft: number, b @action onPointerUp = (e: PointerEvent): void => { SelectionManager.Views().map(dv => { - if (NumCast(dv.layoutDoc._delayAutoHeight) < this._dragHeights.get(dv.layoutDoc)!) { + const hgts = this._dragHeights.get(dv.layoutDoc); + if (hgts && hgts.lowest < hgts.start && hgts.lowest <= 20) { dv.nativeWidth > 0 && Doc.toggleNativeDimensions(dv.layoutDoc, dv.ContentScale(), dv.props.PanelWidth(), dv.props.PanelHeight()); if (dv.layoutDoc._autoHeight) dv.layoutDoc._autoHeight = false; setTimeout(() => dv.layoutDoc._autoHeight = true); } - dv.layoutDoc._delayAutoHeight = undefined; }); this._resizeHdlId = ""; this.Interacting = false; diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index b0c0af002..1fbcd8fa4 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -101,7 +101,7 @@ export class MainView extends React.Component { } new InkStrokeProperties(); this._sidebarContent.proto = undefined; - DocServer.setPlaygroundFields(["x", "y", "dataTransition", "_delayAutoHeight", "_autoHeight", "_showSidebar", "_sidebarWidthPercent", "_width", "_height", "_viewTransition", "_panX", "_panY", "_viewScale", "_scrollTop", "hidden", "_curPage", "_viewType", "_chromeStatus"]); // can play with these fields on someone else's + DocServer.setPlaygroundFields(["x", "y", "dataTransition", "_autoHeight", "_showSidebar", "_sidebarWidthPercent", "_width", "_height", "_viewTransition", "_panX", "_panY", "_viewScale", "_scrollTop", "hidden", "_curPage", "_viewType", "_chromeStatus"]); // can play with these fields on someone else's DocServer.GetRefField("rtfProto").then(proto => (proto instanceof Doc) && reaction(() => StrCast(proto.BROADCAST_MESSAGE), msg => msg && alert(msg))); diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 761485d61..848287fcc 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -1071,16 +1071,12 @@ export class DocumentView extends React.Component<DocumentViewProps> { screenToLocalTransform = () => { return this.props.ScreenToLocalTransform().translate(-this.centeringX, -this.centeringY).scale(1 / this.nativeScaling); } - componentDidMount() { this._disposers.height = reaction( () => NumCast(this.layoutDoc._height), action(height => { const docMax = NumCast(this.layoutDoc.docMaxAutoHeight); if (docMax && docMax < height) this.layoutDoc.docMaxAutoHeight = height; - if (height && height <= 20 && height < NumCast(this.layoutDoc._delayAutoHeight, 20)) { - this.layoutDoc._delayAutoHeight = height; - } }) ); !BoolCast(this.props.Document.dontRegisterView, this.props.dontRegisterView) && DocumentManager.Instance.AddView(this); diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index 76cf6bbc8..d8330372a 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -845,13 +845,16 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp this.props.setContentView?.(this); // this tells the DocumentView that this AudioBox is the "content" of the document. this allows the DocumentView to indirectly call getAnchor() on the AudioBox when making a link. this.props.contentsActive?.(this.IsActive); this._cachedLinks = DocListCast(this.Document.links); - this._disposers.scrollHeight = reaction(() => NumCast(this.rootDoc[this.fieldKey + "-scrollHeight"]), + this._disposers.autoHeight = reaction(() => ({ width: NumCast(this.layoutDoc._width), autoHeight: this.layoutDoc?._autoHeight }), + ({ width, autoHeight }) => width && autoHeight && this.resetNativeHeight(NumCast(this.layoutDoc[this.fieldKey + "-scrollHeight"])) + ); + this._disposers.scrollHeight = reaction(() => NumCast(this.rootDoc[this.fieldKey + "-scrollHeight"]), // if the scroll height changes (from typing), then update the native height if autoHeight is on scrollHeight => this.layoutDoc.autoHeight && this.resetNativeHeight(scrollHeight)); - this._disposers.sidebarheight = reaction( + this._disposers.height = reaction(() => NumCast(this.layoutDoc._height), // if the document height is changed, then make sure the main text height is no bigger than the document height + height => height < NumCast(this.rootDoc[this.fieldKey + "-height"]) && (this.rootDoc[this.fieldKey + "-height"] = height)); + this._disposers.componentHeights = reaction( // set the document height when one of the component heights changes and autoHeight is on () => ({ sidebarHeight: NumCast(this.rootDoc[this.SidebarKey + "-height"]), textHeight: NumCast(this.rootDoc[this.fieldKey + "-height"]) }), - ({ sidebarHeight, textHeight }) => { - this.layoutDoc._autoHeight && this.props.setHeight(Math.max(sidebarHeight, textHeight)); - }); + ({ sidebarHeight, textHeight }) => this.layoutDoc._autoHeight && this.props.setHeight(Math.max(sidebarHeight, textHeight))); this._disposers.links = reaction(() => DocListCast(this.Document.links), // if a link is deleted, then remove all hyperlinks that reference it from the text's marks newLinks => { this._cachedLinks.forEach(l => !newLinks.includes(l) && this.RemoveLinkFromDoc(l)); @@ -906,10 +909,6 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp } } ); - this._disposers.autoHeight = reaction( - () => ({ width: NumCast(this.layoutDoc._width), autoHeight: this.layoutDoc?._autoHeight }), - ({ width, autoHeight }) => width && autoHeight && this.resetNativeHeight(NumCast(this.layoutDoc[this.fieldKey + "-scrollHeight"])) - ); this.setupEditor(this.config, this.props.fieldKey); |