diff --git a/lib/js/src/View/WebviewPanel.bs.js b/lib/js/src/View/WebviewPanel.bs.js index 864ddbf4..49638cb7 100644 --- a/lib/js/src/View/WebviewPanel.bs.js +++ b/lib/js/src/View/WebviewPanel.bs.js @@ -37,7 +37,7 @@ function make(title, extensionPath) { var distPath = Path.join(extensionPath, "dist"); var panel = Vscode.window.createWebviewPanel("panel", title, { preserveFocus: true, - viewColumn: 3 + viewColumn: 8 }, VSCode.WebviewAndWebviewPanelOptions.make(undefined, true, [Vscode.Uri.file(distPath)], undefined, undefined, true, undefined)); var html = makeHTML(panel.webview, extensionPath); panel.webview.html = html; @@ -65,39 +65,13 @@ function reveal(panel) { return VSCode.WebviewPanel.reveal(panel, undefined, true, undefined); } -function moveToBottom(param) { - Vscode.commands.executeCommand((function () { - switch (({ - NAME: "setEditorLayout", - VAL: { - orientation: 1, - groups: [{ size: 0.7 }, { size: 0.3 }] - } - }).NAME) { - case "setEditorLayout" : - return "vscode.setEditorLayout"; - case "setContext" : - return "setContext"; - - } - })(), ({ - NAME: "setEditorLayout", - VAL: { - orientation: 1, - groups: [{ size: 0.7 }, { size: 0.3 }] - } - }).VAL); - -} - var WebviewPanel = { make: make, destroy: destroy, send: send, recv: recv, onDestroyed: onDestroyed, - reveal: reveal, - moveToBottom: moveToBottom + reveal: reveal }; function send$1(view, requestOrEvent) { @@ -164,6 +138,60 @@ function onEvent(view, callback) { } function make$1(title, extensionPath) { + $$Promise.get(Vscode.commands.executeCommand("vscode.getEditorLayout"), (function (layout) { + var mountingPosition = Config$AgdaModeVscode.View.getPanelMountingPosition(undefined); + var orientation = layout.orientation; + var groups = layout.groups; + var match_0 = groups.length; + Vscode.commands.executeCommand((function () { + switch (({ + NAME: "setEditorLayout", + VAL: { + orientation: match_0 !== 1 ? ( + orientation !== 0 ? 0 : 1 + ) : ( + mountingPosition ? 0 : 1 + ), + groups: [ + Curry._1(VSCode.Commands.Layout.sized, { + groups: groups, + size: 0.6 + }), + Curry._1(VSCode.Commands.Layout.sized, { + groups: [VSCode.Commands.Layout.simple], + size: 0.4 + }) + ] + } + }).NAME) { + case "setEditorLayout" : + return "vscode.setEditorLayout"; + case "setContext" : + return "setContext"; + + } + })(), ({ + NAME: "setEditorLayout", + VAL: { + orientation: match_0 !== 1 ? ( + orientation !== 0 ? 0 : 1 + ) : ( + mountingPosition ? 0 : 1 + ), + groups: [ + Curry._1(VSCode.Commands.Layout.sized, { + groups: groups, + size: 0.6 + }), + Curry._1(VSCode.Commands.Layout.sized, { + groups: [VSCode.Commands.Layout.simple], + size: 0.4 + }) + ] + } + }).VAL); + + })); var view = { panel: make(title, extensionPath), onResponse: Chan$AgdaModeVscode.make(undefined), @@ -175,12 +203,6 @@ function make$1(title, extensionPath) { [Symbol.for("name")]: "Uninitialized" } }; - var match = Config$AgdaModeVscode.View.getPanelMountingPosition(undefined); - if (match) { - - } else { - moveToBottom(undefined); - } view.subscriptions.push(view.panel.webview.onDidReceiveMessage(function (json) { var res; try { diff --git a/package-lock.json b/package-lock.json index de615829..4c8725cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7952,4 +7952,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 14969f70..648c45d5 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "reason-nodejs": "github:banacorn/reason-nodejs#temp", "reason-promise": ">=1.1.0", "rescript": "^9.1.4", - "rescript-vscode": "github:banacorn/rescript-vscode#v0.0.17", + "rescript-vscode": "github:banacorn/rescript-vscode#v0.0.18", "untildify": "^4.0.0", "vscode-codicons": "^0.0.7" }, @@ -930,4 +930,4 @@ "publisherDisplayName": "Ting-Gian LUA", "publisherId": "22df016e-6b4f-49b2-9856-3336695d1289" } -} +} \ No newline at end of file diff --git a/src/View/WebviewPanel.res b/src/View/WebviewPanel.res index 710d1dce..6887b0dc 100644 --- a/src/View/WebviewPanel.res +++ b/src/View/WebviewPanel.res @@ -11,10 +11,6 @@ module WebviewPanel: { let onDestroyed: (t, unit => unit) => VSCode.Disposable.t // methods let reveal: t => unit - - // move the panel around - let moveToBottom: unit => unit - // let moveToLeft: unit => unit } = { type t = VSCode.WebviewPanel.t @@ -97,7 +93,7 @@ module WebviewPanel: { let panel = VSCode.Window.createWebviewPanel( "panel", title, - {"preserveFocus": true, "viewColumn": 3}, + {"preserveFocus": true, "viewColumn": 8}, // None, Some( VSCode.WebviewAndWebviewPanelOptions.make( @@ -128,37 +124,6 @@ module WebviewPanel: { let onDestroyed = (panel, callback) => panel->VSCode.WebviewPanel.onDidDispose(callback) let reveal = panel => panel->VSCode.WebviewPanel.reveal(~preserveFocus=true, ()) - - // let moveToLeft = () => { - // open VSCode.Commands - // executeCommand( - // #setEditorLayout({ - // orientation: 0, - // groups: { - // open Layout - // [sized({groups: [simple], size: 0.5}), sized({groups: [simple], size: 0.5})] - // }, - // }), - // )->ignore - // } - - let moveToBottom = () => { - open VSCode.Commands - executeCommand( - #setEditorLayout( - %raw(`{ - orientation: 1, - groups: [{ size: 0.7 }, { size: 0.3 }] - }`) - // { - // orientation: 1, - // groups: { - // open Layout - // [sized({groups: [simple], size: 0.7}), sized({groups: [simple], size: 0.3})] - // }, - ), - )->ignore - } } // a thin layer on top of WebviewPanel @@ -247,20 +212,42 @@ module Module: Module = { view.onEvent->Chan.on(callback)->VSCode.Disposable.make let make = (title, extensionPath) => { - let view = { - panel: WebviewPanel.make(title, extensionPath), - subscriptions: [], - onResponse: Chan.make(), - onEvent: Chan.make(), - status: Uninitialized([], []), - } + open VSCode.Commands - // Move the created panel to the bottom row - switch Config.View.getPanelMountingPosition() { - | Bottom => WebviewPanel.moveToBottom() - | Right => () - } + //Before creating WebviewPanel, update layout by configuration or current layout + getEditorLayout() + ->Promise.get(layout => { + let mountingPosition = Config.View.getPanelMountingPosition() + let orientation = layout.orientation + let groups = layout.groups + + executeCommand( + #setEditorLayout({ + orientation: switch ((Belt.Array.length(groups), mountingPosition), orientation) { + // if there's only one grid, see the configuration + | ((1, Bottom), _) => 1 + | ((1, Right ), _) => 0 + // else see the current layout's orientation + | (_, 0) => 1 + | (_, 1) => 0 + | _ => 0 + }, + groups: { + open Layout + [sized({groups: groups, size: 0.6}), sized({groups: [simple], size: 0.4})] + } + }), + )->ignore + })->ignore + let view = { + panel: WebviewPanel.make(title, extensionPath), + subscriptions: [], + onResponse: Chan.make(), + onEvent: Chan.make(), + status: Uninitialized([], []), + } + // on message // relay Webview.onDidReceiveMessage => onResponse or onEvent view.panel