Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Markdown changes (#2282)
Browse files Browse the repository at this point in the history
* Fix a few small Markdown preview issues.

* Close markdown preview on exit.

* Update marked version.

* Add config option for auto scroll.

* Keep focus on initial split.

* Fix toggle function.

Before the fix was only applied to close.

* Hook up clicking a link to open the Oni browser if activated.

Fixes #2021.

* Fix lint error.

* Update for changed API.

* Update tests.

* Bump package number.

* Update lock file.

* Syntax change.
  • Loading branch information
CrossR committed Jun 19, 2018
1 parent 16c2eb5 commit 7c09bcf
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
6 changes: 5 additions & 1 deletion browser/src/Services/Browser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) => {
Expand Down
7 changes: 6 additions & 1 deletion browser/src/Services/Configuration/DefaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -459,7 +462,9 @@ const LinuxConfigOverrides: Partial<IConfigurationValues> = {

const PlatformConfigOverride = Platform.isWindows()
? WindowsConfigOverrides
: Platform.isLinux() ? LinuxConfigOverrides : MacConfigOverrides
: Platform.isLinux()
? LinuxConfigOverrides
: MacConfigOverrides

export const DefaultConfiguration = {
...BaseConfiguration,
Expand Down
4 changes: 4 additions & 0 deletions browser/src/Services/Configuration/IConfigurationValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion browser/src/Services/WindowManager/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions browser/test/Services/WindowManager/WindowManagerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion extensions/oni-plugin-markdown-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 24 additions & 5 deletions extensions/oni-plugin-markdown-preview/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo
codeForeground: this.props.oni.colors.getColor("foreground"),
codeBorder: this.props.oni.colors.getColor("toolTip.border"),
}

this.state = { source: "", colors }
}

Expand All @@ -58,7 +59,10 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo

this.subscribe(activeEditor.onBufferChanged, args => 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)
}
Expand Down Expand Up @@ -153,6 +157,10 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo
}

private onBufferScrolled(args: Oni.EditorBufferScrolledEventArgs): void {
if (this.props.oni.editors.activeEditor.activeBuffer.language !== "markdown") {
return
}

let anchor = null
for (let line = args.windowTopLine - 1; !anchor && line < args.bufferTotalLines; line++) {
anchor = document.getElementById(generateScrollingAnchorId(line))
Expand All @@ -176,12 +184,14 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo

class MarkdownPreviewEditor implements Oni.IWindowSplit {
private _open: boolean = false
private _manuallyClosed: boolean = false
private _unrenderedContent: string = ""
private _renderedContent: string = ""
private _split: Oni.WindowSplitHandle

constructor(private _oni: Oni.Plugin.Api) {
this._oni.editors.activeEditor.onBufferEnter.subscribe(args => this.onBufferEnter(args))
this._oni.editors.activeEditor.onBufferLeave.subscribe(args => this.onBufferLeave(args))
}

public isPaneOpen(): boolean {
Expand All @@ -203,7 +213,7 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit {

public toggle(): void {
if (this._open) {
this.close()
this.close(true)
} else {
this.open()
}
Expand All @@ -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()
}
}
Expand All @@ -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 {
Expand All @@ -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)
},
),
)
Expand Down
5 changes: 5 additions & 0 deletions main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected].1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.1.tgz#7aed74c14bca2581e1447c557541192dd5e89cdd"
[email protected].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"
Expand Down

0 comments on commit 7c09bcf

Please sign in to comment.