fix: 修复切换 document 时报错

This commit is contained in:
lihao.ylh 2021-08-02 17:14:50 +08:00
parent 06491f90fa
commit 1ad2749c97
3 changed files with 9 additions and 3 deletions

View File

@ -140,7 +140,7 @@ export class OutlineMain implements ISensor, ITreeBoard, IScrollable {
const { nodes } = dragObject; const { nodes } = dragObject;
const tree = this._master?.currentTree; const tree = this._master?.currentTree;
if (!tree || !this._shell) { if (!tree || !tree.root || !this._shell) {
return null; return null;
} }

View File

@ -7,9 +7,12 @@ export class Tree {
readonly id: string; readonly id: string;
@computed get root(): TreeNode { @computed get root(): TreeNode | null {
if (this.document.focusNode) {
return this.getTreeNode(this.document.focusNode!); return this.getTreeNode(this.document.focusNode!);
} }
return null;
}
constructor(readonly document: DocumentModel) { constructor(readonly document: DocumentModel) {
this.id = document.id; this.id = document.id;

View File

@ -150,6 +150,9 @@ export default class TreeView extends Component<{ tree: Tree }> {
render() { render() {
const { tree } = this.props; const { tree } = this.props;
const { root } = tree; const { root } = tree;
if (!root) {
return null;
}
return ( return (
<div <div
className="lc-outline-tree" className="lc-outline-tree"