From 4e11efb341244662a1870313095496c277a7c741 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 4 May 2022 11:53:14 +0800 Subject: [PATCH] ui: milkdown: handle editor layout --- .../components/editor/cmeditor.styl | 14 +++++++++++ .../ui-default/components/editor/index.ts | 25 +++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/ui-default/components/editor/cmeditor.styl b/packages/ui-default/components/editor/cmeditor.styl index 5474f21b7..f7dc1ca7c 100644 --- a/packages/ui-default/components/editor/cmeditor.styl +++ b/packages/ui-default/components/editor/cmeditor.styl @@ -5,3 +5,17 @@ .code-fence_selector height: 2.2em !important width: 10em !important + +.editor-root + width: 100% + height: 100% + +.editor-main + width: 100% + height: 100% + display: inline-flex + +.editor-col + min-width: 50% + padding-left: 0px + padding-right: 0px diff --git a/packages/ui-default/components/editor/index.ts b/packages/ui-default/components/editor/index.ts index f28fc79e4..285d05d7a 100644 --- a/packages/ui-default/components/editor/index.ts +++ b/packages/ui-default/components/editor/index.ts @@ -20,6 +20,9 @@ export default class VjEditor extends DOMAttachedObject { static DOMAttachKey = 'vjEditorInstance'; isValid: boolean; private lock: boolean; + height = 0; + menu: JQuery; + root: JQuery; model: import('../monaco').default.editor.IModel; editor: import('../monaco').default.editor.IStandaloneCodeEditor; milkdown: import('@milkdown/core').Editor & { @@ -28,16 +31,17 @@ export default class VjEditor extends DOMAttachedObject { dispose?: () => void; }; - height = 0; - constructor($dom, public options: Options = {}) { super($dom); $dom.hide(); - const root = $('
'); - const left = $('
'); - const right = $('
'); - root.append(left, right); - $($dom).parent().append(root); + this.root = $('
'); + this.menu = $('
'); + const editor = $('
'); + const left = $('
'); + const right = $(''); + this.root.append(this.menu, editor); + editor.append(left, right); + $($dom).parent().append(this.root); this.initMonaco(left.get(0)); if ((options?.language || 'markdown') === 'markdown') this.initMilkdown(right.get(0)); } @@ -53,7 +57,6 @@ export default class VjEditor extends DOMAttachedObject { } = this.options; const { monaco, registerAction } = await load([language]); const hasFocus = this.$dom.is(':focus') || this.$dom.hasClass('autofocus'); - if (!autoResize && this.$dom.height()) $(ele).height(this.$dom.height()); const value = this.options.value || this.$dom.val(); this.model = typeof model === 'string' ? monaco.editor.getModel(monaco.Uri.parse(model)) @@ -240,8 +243,9 @@ export default class VjEditor extends DOMAttachedObject { view?.destroy(); }; await this.milkdown.create(); - $('.editor-root').prepend($('
')); - $('.editor-menu').prepend($('.milkdown-menu')); + $(ele).show(); + this.menu.children().remove(); + this.menu.prepend(this.root.find('.milkdown-menu')); this.isValid = true; } @@ -249,6 +253,7 @@ export default class VjEditor extends DOMAttachedObject { this.detach(); this.editor?.dispose(); this.milkdown?.dispose(); + this.root?.remove(); } ensureValid() {