From e2ac28a6e5061330cf461666ef8938cee609a3af Mon Sep 17 00:00:00 2001 From: spacedragon Date: Mon, 22 Jul 2019 10:14:39 +0800 Subject: [PATCH] [Code] test colorize before load a file --- .../legacy/plugins/code/public/components/editor/editor.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/legacy/plugins/code/public/components/editor/editor.tsx b/x-pack/legacy/plugins/code/public/components/editor/editor.tsx index 10b3f1954d354..b186f3b7896dd 100644 --- a/x-pack/legacy/plugins/code/public/components/editor/editor.tsx +++ b/x-pack/legacy/plugins/code/public/components/editor/editor.tsx @@ -199,6 +199,12 @@ export class EditorComponent extends React.Component { private async loadText(text: string, repo: string, file: string, lang: string, revision: string) { if (this.monaco) { + try { + await monaco.editor.colorize(text, lang, {}); + } catch (e) { + // workaround a upstream issue: https://github.com/microsoft/monaco-editor/issues/134 + lang = 'text'; + } this.editor = await this.monaco.loadFile(repo, file, text, lang, revision); this.registerGutterClickHandler(); }