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 tree = this._master?.currentTree;
if (!tree || !this._shell) {
if (!tree || !tree.root || !this._shell) {
return null;
}

View File

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

View File

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