From 126eac483330991c579deb4279e6c58231e0ccb4 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 26 Feb 2019 14:32:16 +0800 Subject: [PATCH] [Code] fix editor lifecycle method (#31983) --- .../code/public/components/editor/editor.tsx | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/code/public/components/editor/editor.tsx b/x-pack/plugins/code/public/components/editor/editor.tsx index 1b9e703598445..134b0c659638f 100644 --- a/x-pack/plugins/code/public/components/editor/editor.tsx +++ b/x-pack/plugins/code/public/components/editor/editor.tsx @@ -76,8 +76,7 @@ export class EditorComponent extends React.Component { this.revealPosition(this.props.revealPosition); } const { file } = this.props; - const currentFileContent = this.props.file.content; - if (file.content && file.content !== currentFileContent) { + if (file.content && prevProps.file.content !== file.content) { const { uri, path, revision } = file.payload; this.loadText(file.content, uri, path, file.lang!, revision).then(() => { if (this.props.revealPosition) { @@ -85,16 +84,18 @@ export class EditorComponent extends React.Component { } }); } - if (prevProps.showBlame !== this.props.showBlame && this.props.showBlame) { - this.loadBlame(this.props.blames); - this.monaco!.editor!.updateOptions({ lineHeight: 38 }); - } else if (!this.props.showBlame) { - this.destroyBlameWidgets(); - this.monaco!.editor!.updateOptions({ lineHeight: 24 }); - } - if (prevProps.blames !== this.props.blames && this.props.showBlame) { - this.loadBlame(this.props.blames); - this.monaco!.editor!.updateOptions({ lineHeight: 38 }); + if (this.monaco && this.monaco.editor) { + if (prevProps.showBlame !== this.props.showBlame && this.props.showBlame) { + this.loadBlame(this.props.blames); + this.monaco.editor.updateOptions({ lineHeight: 38 }); + } else if (!this.props.showBlame) { + this.destroyBlameWidgets(); + this.monaco.editor.updateOptions({ lineHeight: 24 }); + } + if (prevProps.blames !== this.props.blames && this.props.showBlame) { + this.loadBlame(this.props.blames); + this.monaco.editor.updateOptions({ lineHeight: 38 }); + } } }