diff --git a/browser/src/Services/Browser/index.tsx b/browser/src/Services/Browser/index.tsx index 0cf849ea18..d164714dd8 100644 --- a/browser/src/Services/Browser/index.tsx +++ b/browser/src/Services/Browser/index.tsx @@ -4,7 +4,7 @@ * Entry point for browser integration plugin */ -import { shell, WebviewTag } from "electron" +import { ipcRenderer, shell, WebviewTag } from "electron" import * as React from "react" import * as Oni from "oni-api" @@ -290,6 +290,10 @@ export const activate = ( detail: "", enabled: isBrowserScrollCommandEnabled, }) + + ipcRenderer.on("open-oni-browser", (event: string, args: string) => { + openUrl(args) + }) } export const registerAchievements = (achievements: AchievementsManager) => { diff --git a/browser/src/Services/Configuration/DefaultConfiguration.ts b/browser/src/Services/Configuration/DefaultConfiguration.ts index 79bdae8a29..2b9dc36174 100644 --- a/browser/src/Services/Configuration/DefaultConfiguration.ts +++ b/browser/src/Services/Configuration/DefaultConfiguration.ts @@ -57,6 +57,9 @@ const BaseConfiguration: IConfigurationValues = { "experimental.preview.enabled": false, "experimental.welcome.enabled": false, + "experimental.markdownPreview.enabled": false, + "experimental.markdownPreview.autoScroll": true, + "experimental.neovim.transport": "stdio", // TODO: Enable pipe transport for Windows // "experimental.neovim.transport": Platform.isWindows() ? "pipe" : "stdio", @@ -459,7 +462,9 @@ const LinuxConfigOverrides: Partial = { const PlatformConfigOverride = Platform.isWindows() ? WindowsConfigOverrides - : Platform.isLinux() ? LinuxConfigOverrides : MacConfigOverrides + : Platform.isLinux() + ? LinuxConfigOverrides + : MacConfigOverrides export const DefaultConfiguration = { ...BaseConfiguration, diff --git a/browser/src/Services/Configuration/IConfigurationValues.ts b/browser/src/Services/Configuration/IConfigurationValues.ts index 60eb8ad501..9bc579aea1 100644 --- a/browser/src/Services/Configuration/IConfigurationValues.ts +++ b/browser/src/Services/Configuration/IConfigurationValues.ts @@ -49,6 +49,10 @@ export interface IConfigurationValues { // Whether or not the learning pane is available "experimental.particles.enabled": boolean + // Whether the markdown preview pane should be shown + "experimental.markdownPreview.enabled": boolean + "experimental.markdownPreview.autoScroll": boolean + // The transport to use for Neovim // Valid values are "stdio" and "pipe" "experimental.neovim.transport": string diff --git a/browser/src/Services/WindowManager/WindowManager.ts b/browser/src/Services/WindowManager/WindowManager.ts index 5793f30c11..886135c3da 100644 --- a/browser/src/Services/WindowManager/WindowManager.ts +++ b/browser/src/Services/WindowManager/WindowManager.ts @@ -137,7 +137,11 @@ export class WindowManager { return this._store } - public get activeSplit(): IAugmentedSplitInfo { + get activeSplitHandle(): WindowSplitHandle { + return new WindowSplitHandle(this._store, this, this.activeSplit.id) + } + + private get activeSplit(): IAugmentedSplitInfo { const focusedSplit = this._store.getState().focusedSplitId if (!focusedSplit) { diff --git a/browser/test/Services/WindowManager/WindowManagerTests.ts b/browser/test/Services/WindowManager/WindowManagerTests.ts index 8e836d6c90..589d658892 100644 --- a/browser/test/Services/WindowManager/WindowManagerTests.ts +++ b/browser/test/Services/WindowManager/WindowManagerTests.ts @@ -22,18 +22,18 @@ describe("WindowManagerTests", () => { const handle1 = windowManager.createSplit("horizontal", split1) const handle2 = windowManager.createSplit("vertical", split2, split1) - assert.strictEqual(windowManager.activeSplit.id, handle2.id) + assert.strictEqual(windowManager.activeSplitHandle.id, handle2.id) handle2.close() - assert.strictEqual(windowManager.activeSplit.id, handle1.id) + assert.strictEqual(windowManager.activeSplitHandle.id, handle1.id) const handle3 = windowManager.createSplit("horizontal", split3, split1) - assert.strictEqual(windowManager.activeSplit.id, handle3.id) + assert.strictEqual(windowManager.activeSplitHandle.id, handle3.id) handle3.close() - assert.strictEqual(windowManager.activeSplit.id, handle1.id) + assert.strictEqual(windowManager.activeSplitHandle.id, handle1.id) }) it("can get split after a split is closed", async () => { diff --git a/extensions/oni-plugin-markdown-preview/package.json b/extensions/oni-plugin-markdown-preview/package.json index d27bf36027..a890d11ac3 100644 --- a/extensions/oni-plugin-markdown-preview/package.json +++ b/extensions/oni-plugin-markdown-preview/package.json @@ -21,7 +21,7 @@ } }, "tbd-dependencies": { - "marked": "^0.3.6", + "marked": "^0.4.0", "dompurify": "1.0.2", "oni-types": "^0.0.4", "oni-api": "^0.0.9" diff --git a/extensions/oni-plugin-markdown-preview/src/index.tsx b/extensions/oni-plugin-markdown-preview/src/index.tsx index 516b4efe12..cf5479ecf3 100644 --- a/extensions/oni-plugin-markdown-preview/src/index.tsx +++ b/extensions/oni-plugin-markdown-preview/src/index.tsx @@ -46,6 +46,7 @@ class MarkdownPreview extends React.PureComponent this.onBufferChanged(args)) // TODO: Subscribe "onFocusChanged" - this.subscribe(activeEditor.onBufferScrolled, args => this.onBufferScrolled(args)) + + if (this.props.oni.configuration.getValue("experimental.markdownPreview.autoScroll")) { + this.subscribe(activeEditor.onBufferScrolled, args => this.onBufferScrolled(args)) + } this.previewBuffer(activeEditor.activeBuffer) } @@ -153,6 +157,10 @@ class MarkdownPreview extends React.PureComponent this.onBufferEnter(args)) + this._oni.editors.activeEditor.onBufferLeave.subscribe(args => this.onBufferLeave(args)) } public isPaneOpen(): boolean { @@ -203,7 +213,7 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit { public toggle(): void { if (this._open) { - this.close() + this.close(true) } else { this.open() } @@ -212,14 +222,19 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit { public open(): void { if (!this._open) { this._open = true + this._manuallyClosed = false + const editorSplit = this._oni.windows.activeSplitHandle + // TODO: Update API this._split = this._oni.windows.createSplit("vertical", this) + editorSplit.focus() } } - public close(): void { + public close(manuallyClosed = false): void { if (this._open) { this._open = false + this._manuallyClosed = manuallyClosed this._split.close() } } @@ -229,10 +244,14 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit { } private onBufferEnter(bufferInfo: Oni.EditorBufferEventArgs): void { - if (bufferInfo.language === "markdown") { + if (bufferInfo.language === "markdown" && this._manuallyClosed === false) { this.open() } } + + private onBufferLeave(bufferInfo: Oni.EditorBufferEventArgs): void { + this.close() + } } export function activate(oni: any): any { @@ -259,7 +278,7 @@ export function activate(oni: any): any { "Close Markdown Preview", "Close the Markdown preview pane if it is not already closed", () => { - preview.close() + preview.close(true) }, ), ) diff --git a/main/src/main.ts b/main/src/main.ts index 3b68a2404a..8774469fd6 100644 --- a/main/src/main.ts +++ b/main/src/main.ts @@ -242,6 +242,11 @@ export function createWindow( Log.info("...closed event completed") }) + currentWindow.webContents.on("will-navigate", (event, url) => { + event.preventDefault() + currentWindow.webContents.send("open-oni-browser", url) + }) + windows.push(currentWindow) return currentWindow diff --git a/package.json b/package.json index 6d57860b64..47e9c40b38 100644 --- a/package.json +++ b/package.json @@ -856,11 +856,11 @@ "fs-extra": "^5.0.0", "json5": "^1.0.1", "keyboard-layout": "^2.0.13", - "marked": "^0.3.6", + "marked": "^0.4.0", "minimist": "1.2.0", "msgpack-lite": "0.1.26", "ocaml-language-server": "^1.0.27", - "oni-api": "^0.0.45", + "oni-api": "^0.0.46", "oni-neovim-binaries": "0.1.2", "oni-ripgrep": "0.0.4", "oni-types": "^0.0.8", diff --git a/yarn.lock b/yarn.lock index 5029183876..15d7705b8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6537,9 +6537,9 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" -marked@^0.3.6: - version "0.3.7" - resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.7.tgz#80ef3bbf1bd00d1c9cfebe42ba1b8c85da258d0d" +marked@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/marked/-/marked-0.4.0.tgz#9ad2c2a7a1791f10a852e0112f77b571dce10c66" math-expression-evaluator@^1.2.14: version "1.2.17" @@ -7333,17 +7333,17 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" -oni-api@^0.0.45: - version "0.0.45" - resolved "https://registry.yarnpkg.com/oni-api/-/oni-api-0.0.45.tgz#e9191fbc5069e01b3cbea644bc697be9aaf1d699" +oni-api@^0.0.46: + version "0.0.46" + resolved "https://registry.yarnpkg.com/oni-api/-/oni-api-0.0.46.tgz#99511a0c5488af1762b4744ce1ca79fea45b2b8b" oni-core-logging@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/oni-core-logging/-/oni-core-logging-1.0.0.tgz#7ad6c0ad8b06c23255202f97e229c2b0947dcf0b" -oni-neovim-binaries@0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.1.tgz#7aed74c14bca2581e1447c557541192dd5e89cdd" +oni-neovim-binaries@0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.2.tgz#fccfab6aa71922437119a8de149582648f4e521d" oni-release-downloader@^0.0.10: version "0.0.10"