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

Commit 7c09bcf

Browse files
authored
Markdown changes (#2282)
* 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.
1 parent 16c2eb5 commit 7c09bcf

File tree

10 files changed

+65
-24
lines changed

10 files changed

+65
-24
lines changed

browser/src/Services/Browser/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Entry point for browser integration plugin
55
*/
66

7-
import { shell, WebviewTag } from "electron"
7+
import { ipcRenderer, shell, WebviewTag } from "electron"
88
import * as React from "react"
99

1010
import * as Oni from "oni-api"
@@ -290,6 +290,10 @@ export const activate = (
290290
detail: "",
291291
enabled: isBrowserScrollCommandEnabled,
292292
})
293+
294+
ipcRenderer.on("open-oni-browser", (event: string, args: string) => {
295+
openUrl(args)
296+
})
293297
}
294298

295299
export const registerAchievements = (achievements: AchievementsManager) => {

browser/src/Services/Configuration/DefaultConfiguration.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const BaseConfiguration: IConfigurationValues = {
5757
"experimental.preview.enabled": false,
5858
"experimental.welcome.enabled": false,
5959

60+
"experimental.markdownPreview.enabled": false,
61+
"experimental.markdownPreview.autoScroll": true,
62+
6063
"experimental.neovim.transport": "stdio",
6164
// TODO: Enable pipe transport for Windows
6265
// "experimental.neovim.transport": Platform.isWindows() ? "pipe" : "stdio",
@@ -459,7 +462,9 @@ const LinuxConfigOverrides: Partial<IConfigurationValues> = {
459462

460463
const PlatformConfigOverride = Platform.isWindows()
461464
? WindowsConfigOverrides
462-
: Platform.isLinux() ? LinuxConfigOverrides : MacConfigOverrides
465+
: Platform.isLinux()
466+
? LinuxConfigOverrides
467+
: MacConfigOverrides
463468

464469
export const DefaultConfiguration = {
465470
...BaseConfiguration,

browser/src/Services/Configuration/IConfigurationValues.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export interface IConfigurationValues {
4949
// Whether or not the learning pane is available
5050
"experimental.particles.enabled": boolean
5151

52+
// Whether the markdown preview pane should be shown
53+
"experimental.markdownPreview.enabled": boolean
54+
"experimental.markdownPreview.autoScroll": boolean
55+
5256
// The transport to use for Neovim
5357
// Valid values are "stdio" and "pipe"
5458
"experimental.neovim.transport": string

browser/src/Services/WindowManager/WindowManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ export class WindowManager {
137137
return this._store
138138
}
139139

140-
public get activeSplit(): IAugmentedSplitInfo {
140+
get activeSplitHandle(): WindowSplitHandle {
141+
return new WindowSplitHandle(this._store, this, this.activeSplit.id)
142+
}
143+
144+
private get activeSplit(): IAugmentedSplitInfo {
141145
const focusedSplit = this._store.getState().focusedSplitId
142146

143147
if (!focusedSplit) {

browser/test/Services/WindowManager/WindowManagerTests.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ describe("WindowManagerTests", () => {
2222
const handle1 = windowManager.createSplit("horizontal", split1)
2323
const handle2 = windowManager.createSplit("vertical", split2, split1)
2424

25-
assert.strictEqual(windowManager.activeSplit.id, handle2.id)
25+
assert.strictEqual(windowManager.activeSplitHandle.id, handle2.id)
2626

2727
handle2.close()
2828

29-
assert.strictEqual(windowManager.activeSplit.id, handle1.id)
29+
assert.strictEqual(windowManager.activeSplitHandle.id, handle1.id)
3030

3131
const handle3 = windowManager.createSplit("horizontal", split3, split1)
32-
assert.strictEqual(windowManager.activeSplit.id, handle3.id)
32+
assert.strictEqual(windowManager.activeSplitHandle.id, handle3.id)
3333

3434
handle3.close()
3535

36-
assert.strictEqual(windowManager.activeSplit.id, handle1.id)
36+
assert.strictEqual(windowManager.activeSplitHandle.id, handle1.id)
3737
})
3838

3939
it("can get split after a split is closed", async () => {

extensions/oni-plugin-markdown-preview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
},
2323
"tbd-dependencies": {
24-
"marked": "^0.3.6",
24+
"marked": "^0.4.0",
2525
"dompurify": "1.0.2",
2626
"oni-types": "^0.0.4",
2727
"oni-api": "^0.0.9"

extensions/oni-plugin-markdown-preview/src/index.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo
4646
codeForeground: this.props.oni.colors.getColor("foreground"),
4747
codeBorder: this.props.oni.colors.getColor("toolTip.border"),
4848
}
49+
4950
this.state = { source: "", colors }
5051
}
5152

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

5960
this.subscribe(activeEditor.onBufferChanged, args => this.onBufferChanged(args))
6061
// TODO: Subscribe "onFocusChanged"
61-
this.subscribe(activeEditor.onBufferScrolled, args => this.onBufferScrolled(args))
62+
63+
if (this.props.oni.configuration.getValue("experimental.markdownPreview.autoScroll")) {
64+
this.subscribe(activeEditor.onBufferScrolled, args => this.onBufferScrolled(args))
65+
}
6266

6367
this.previewBuffer(activeEditor.activeBuffer)
6468
}
@@ -153,6 +157,10 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo
153157
}
154158

155159
private onBufferScrolled(args: Oni.EditorBufferScrolledEventArgs): void {
160+
if (this.props.oni.editors.activeEditor.activeBuffer.language !== "markdown") {
161+
return
162+
}
163+
156164
let anchor = null
157165
for (let line = args.windowTopLine - 1; !anchor && line < args.bufferTotalLines; line++) {
158166
anchor = document.getElementById(generateScrollingAnchorId(line))
@@ -176,12 +184,14 @@ class MarkdownPreview extends React.PureComponent<IMarkdownPreviewProps, IMarkdo
176184

177185
class MarkdownPreviewEditor implements Oni.IWindowSplit {
178186
private _open: boolean = false
187+
private _manuallyClosed: boolean = false
179188
private _unrenderedContent: string = ""
180189
private _renderedContent: string = ""
181190
private _split: Oni.WindowSplitHandle
182191

183192
constructor(private _oni: Oni.Plugin.Api) {
184193
this._oni.editors.activeEditor.onBufferEnter.subscribe(args => this.onBufferEnter(args))
194+
this._oni.editors.activeEditor.onBufferLeave.subscribe(args => this.onBufferLeave(args))
185195
}
186196

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

204214
public toggle(): void {
205215
if (this._open) {
206-
this.close()
216+
this.close(true)
207217
} else {
208218
this.open()
209219
}
@@ -212,14 +222,19 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit {
212222
public open(): void {
213223
if (!this._open) {
214224
this._open = true
225+
this._manuallyClosed = false
226+
const editorSplit = this._oni.windows.activeSplitHandle
227+
215228
// TODO: Update API
216229
this._split = this._oni.windows.createSplit("vertical", this)
230+
editorSplit.focus()
217231
}
218232
}
219233

220-
public close(): void {
234+
public close(manuallyClosed = false): void {
221235
if (this._open) {
222236
this._open = false
237+
this._manuallyClosed = manuallyClosed
223238
this._split.close()
224239
}
225240
}
@@ -229,10 +244,14 @@ class MarkdownPreviewEditor implements Oni.IWindowSplit {
229244
}
230245

231246
private onBufferEnter(bufferInfo: Oni.EditorBufferEventArgs): void {
232-
if (bufferInfo.language === "markdown") {
247+
if (bufferInfo.language === "markdown" && this._manuallyClosed === false) {
233248
this.open()
234249
}
235250
}
251+
252+
private onBufferLeave(bufferInfo: Oni.EditorBufferEventArgs): void {
253+
this.close()
254+
}
236255
}
237256

238257
export function activate(oni: any): any {
@@ -259,7 +278,7 @@ export function activate(oni: any): any {
259278
"Close Markdown Preview",
260279
"Close the Markdown preview pane if it is not already closed",
261280
() => {
262-
preview.close()
281+
preview.close(true)
263282
},
264283
),
265284
)

main/src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ export function createWindow(
242242
Log.info("...closed event completed")
243243
})
244244

245+
currentWindow.webContents.on("will-navigate", (event, url) => {
246+
event.preventDefault()
247+
currentWindow.webContents.send("open-oni-browser", url)
248+
})
249+
245250
windows.push(currentWindow)
246251

247252
return currentWindow

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,11 @@
856856
"fs-extra": "^5.0.0",
857857
"json5": "^1.0.1",
858858
"keyboard-layout": "^2.0.13",
859-
"marked": "^0.3.6",
859+
"marked": "^0.4.0",
860860
"minimist": "1.2.0",
861861
"msgpack-lite": "0.1.26",
862862
"ocaml-language-server": "^1.0.27",
863-
"oni-api": "^0.0.45",
863+
"oni-api": "^0.0.46",
864864
"oni-neovim-binaries": "0.1.2",
865865
"oni-ripgrep": "0.0.4",
866866
"oni-types": "^0.0.8",

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6537,9 +6537,9 @@ map-visit@^1.0.0:
65376537
dependencies:
65386538
object-visit "^1.0.0"
65396539

6540-
marked@^0.3.6:
6541-
version "0.3.7"
6542-
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.7.tgz#80ef3bbf1bd00d1c9cfebe42ba1b8c85da258d0d"
6540+
marked@^0.4.0:
6541+
version "0.4.0"
6542+
resolved "https://registry.yarnpkg.com/marked/-/marked-0.4.0.tgz#9ad2c2a7a1791f10a852e0112f77b571dce10c66"
65436543

65446544
math-expression-evaluator@^1.2.14:
65456545
version "1.2.17"
@@ -7333,17 +7333,17 @@ onetime@^2.0.0:
73337333
dependencies:
73347334
mimic-fn "^1.0.0"
73357335

7336-
oni-api@^0.0.45:
7337-
version "0.0.45"
7338-
resolved "https://registry.yarnpkg.com/oni-api/-/oni-api-0.0.45.tgz#e9191fbc5069e01b3cbea644bc697be9aaf1d699"
7336+
oni-api@^0.0.46:
7337+
version "0.0.46"
7338+
resolved "https://registry.yarnpkg.com/oni-api/-/oni-api-0.0.46.tgz#99511a0c5488af1762b4744ce1ca79fea45b2b8b"
73397339

73407340
oni-core-logging@^1.0.0:
73417341
version "1.0.0"
73427342
resolved "https://registry.yarnpkg.com/oni-core-logging/-/oni-core-logging-1.0.0.tgz#7ad6c0ad8b06c23255202f97e229c2b0947dcf0b"
73437343

7344-
7345-
version "0.1.1"
7346-
resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.1.tgz#7aed74c14bca2581e1447c557541192dd5e89cdd"
7344+
7345+
version "0.1.2"
7346+
resolved "https://registry.yarnpkg.com/oni-neovim-binaries/-/oni-neovim-binaries-0.1.2.tgz#fccfab6aa71922437119a8de149582648f4e521d"
73477347

73487348
oni-release-downloader@^0.0.10:
73497349
version "0.0.10"

0 commit comments

Comments
 (0)