diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/collections/TreeView.tsx | 5 | ||||
-rw-r--r-- | src/client/views/nodes/trails/PresBox.tsx | 30 |
2 files changed, 19 insertions, 16 deletions
diff --git a/src/client/views/collections/TreeView.tsx b/src/client/views/collections/TreeView.tsx index 23b6a7f72..a85b2a0d4 100644 --- a/src/client/views/collections/TreeView.tsx +++ b/src/client/views/collections/TreeView.tsx @@ -216,8 +216,11 @@ export class TreeView extends React.Component<TreeViewProps> { this.props.hierarchyIndex !== undefined && this.props.RemFromMap?.(this.doc, this.props.hierarchyIndex); } + componentDidUpdate() { + this.props.hierarchyIndex !== undefined && this.props.AddToMap?.(this.doc, this.props.hierarchyIndex); + } + componentDidMount() { - // TODO: [AL] add these this.props.hierarchyIndex !== undefined && this.props.AddToMap?.(this.doc, this.props.hierarchyIndex); } diff --git a/src/client/views/nodes/trails/PresBox.tsx b/src/client/views/nodes/trails/PresBox.tsx index dea6b818f..aa89b8b6c 100644 --- a/src/client/views/nodes/trails/PresBox.tsx +++ b/src/client/views/nodes/trails/PresBox.tsx @@ -103,7 +103,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() { // @computed get childDocs() { return DocListCast(this.rootDoc.presentationaLinearizedDocuments); } //_treeViewMap:Map<number[], Doc> @computed get childDocs() { return this.layoutDoc._viewType === CollectionViewType.Tree ? DocListCast(this.rootDoc.presentationLinearizedDocuments) : DocListCast(this.rootDoc[this.fieldKey]); } - @observable _treeViewMap: Map<number, Doc> = new Map<number, Doc>(); + @observable _treeViewMap: Map<Doc, number> = new Map(); @computed get tagDocs() { const tagDocs: Doc[] = []; @@ -2454,27 +2454,21 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() { for (let i = 0; i < index.length; i++) { indexNum += (index[i] * (10 ** (-i))); } - this._treeViewMap.set(indexNum, treeViewDoc); - this.props.Document.presentationLinearizedDocuments = new List<Doc>(this.sort(this._treeViewMap)); // this is a flat array of Docs + if (this._treeViewMap.get(treeViewDoc) !== indexNum) { + this._treeViewMap.set(treeViewDoc, indexNum); + this.props.Document.presentationLinearizedDocuments = new List<Doc>(this.sort(this._treeViewMap)); // this is a flat array of Docs + } return this.childDocs; } RemFromMap = (treeViewDoc: Doc, index: number[]): Doc[] => { - var indexNum = 0; - for (let i = 0; i < index.length; i++) { - indexNum += (index[i] * (10 ** (-i))); - } - console.log(String(index), treeViewDoc) - this._treeViewMap.delete(indexNum); - const overlay = (Doc.UserDoc().myOverlayDocs as Doc); - if (!DocListCast(overlay[Doc.LayoutFieldKey(overlay)]).includes(this.rootDoc)) { - this.props.Document.presentationLinearizedDocuments = new List<Doc>(this.sort(this._treeViewMap)); - } + this._treeViewMap.delete(treeViewDoc); + this.props.Document.presentationLinearizedDocuments = new List<Doc>(this.sort(this._treeViewMap)); return this.childDocs; } // TODO: [AL] implement sort function for an array of numbers (e.g. arr[1,2,4] v arr[1,2,1]) - sort = (treeViewMap: Map<number, Doc>) => [...treeViewMap.entries()].sort().map(kv => kv[1]); + sort = (treeViewMap: Map<Doc, number>) => [...treeViewMap.entries()].sort((a: [Doc, number], b: [Doc, number]) => a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : 0).map(kv => kv[0]); render() { // calling this method for keyEvents @@ -2552,7 +2546,13 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps>() { } // this func communicates with PresBoxElement to send information of the doc ScriptingGlobals.add(function lookupPresBoxField(presBoxDoc: Doc, field: string, presEleDoc: Doc) { - if (field === 'indexInPres') return DocListCast(presBoxDoc._viewType === CollectionViewType.Tree ? presBoxDoc.presentationLinearizedDocuments : presBoxDoc[StrCast(presBoxDoc.presentationFieldKey)]).indexOf(presEleDoc); + if (field === 'indexInPres') { + const ind = DocListCast(presBoxDoc._viewType === CollectionViewType.Tree ? presBoxDoc.presentationLinearizedDocuments : presBoxDoc[StrCast(presBoxDoc.presentationFieldKey)]).indexOf(presEleDoc); + if (ind === -1) { + console.log(); + } + return ind; + } if (field === 'presCollapsedHeight') return [CollectionViewType.Tree || CollectionViewType.Stacking].includes(presBoxDoc._viewType as any) ? 35 : 31; if (field === 'presStatus') return presBoxDoc.presStatus; if (field === '_itemIndex') return presBoxDoc._itemIndex; |