forked from christianvoigt/argdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(argdown-vscode): fixes resource paths,
updates preview code based on changes in VSCode's Markdown preview
- Loading branch information
1 parent
8a1be2d
commit 79818c3
Showing
20 changed files
with
1,802 additions
and
987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"endOfLine": "lf" | ||
"endOfLine": "lf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,91 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
import { Command } from './Command'; | ||
import { ArgdownPreviewManager } from '../preview/ArgdownPreviewManager'; | ||
import { PreviewSettings } from '../preview/ArgdownPreview'; | ||
|
||
|
||
function getViewColumn(sideBySide: boolean): vscode.ViewColumn | undefined { | ||
const active = vscode.window.activeTextEditor; | ||
if (!active) { | ||
return vscode.ViewColumn.One; | ||
} | ||
|
||
if (!sideBySide) { | ||
return active.viewColumn; | ||
} | ||
|
||
switch (active.viewColumn) { | ||
case vscode.ViewColumn.One: | ||
return vscode.ViewColumn.Two; | ||
case vscode.ViewColumn.Two: | ||
return vscode.ViewColumn.Three; | ||
} | ||
|
||
return active.viewColumn; | ||
} | ||
|
||
interface IShowPreviewSettings { | ||
readonly sideBySide?: boolean; | ||
readonly locked?: boolean; | ||
import * as vscode from "vscode"; | ||
import { Command } from "./Command"; | ||
import { | ||
DynamicPreviewSettings, | ||
ArgdownPreviewManager | ||
} from "../preview/ArgdownPreviewManager"; | ||
|
||
interface ShowPreviewSettings { | ||
readonly sideBySide?: boolean; | ||
readonly locked?: boolean; | ||
} | ||
|
||
async function showPreview( | ||
webviewManager: ArgdownPreviewManager, | ||
uri: vscode.Uri | undefined, | ||
previewSettings: IShowPreviewSettings, | ||
webviewManager: ArgdownPreviewManager, | ||
uri: vscode.Uri | undefined, | ||
previewSettings: ShowPreviewSettings | ||
): Promise<any> { | ||
let resource = uri; | ||
if (!(resource instanceof vscode.Uri)) { | ||
if (vscode.window.activeTextEditor) { | ||
// we are relaxed and don't check for argdown files | ||
resource = vscode.window.activeTextEditor.document.uri; | ||
} | ||
} | ||
|
||
if (!(resource instanceof vscode.Uri)) { | ||
if (!vscode.window.activeTextEditor) { | ||
// this is most likely toggling the preview | ||
return vscode.commands.executeCommand('argdown.showSource'); | ||
} | ||
// nothing found that could be shown or toggled | ||
return; | ||
} | ||
|
||
webviewManager.preview(resource, { | ||
resourceColumn: (vscode.window.activeTextEditor && vscode.window.activeTextEditor.viewColumn) || vscode.ViewColumn.One, | ||
previewColumn: getViewColumn(!!previewSettings.sideBySide) || vscode.ViewColumn.Active, | ||
locked: !!previewSettings.locked | ||
}); | ||
|
||
let resource = uri; | ||
if (!(resource instanceof vscode.Uri)) { | ||
if (vscode.window.activeTextEditor) { | ||
// we are relaxed and don't check for argdown files | ||
resource = vscode.window.activeTextEditor.document.uri; | ||
} | ||
} | ||
|
||
if (!(resource instanceof vscode.Uri)) { | ||
if (!vscode.window.activeTextEditor) { | ||
// this is most likely toggling the preview | ||
return vscode.commands.executeCommand("argdown.showSource"); | ||
} | ||
// nothing found that could be shown or toggled | ||
return; | ||
} | ||
|
||
const resourceColumn = | ||
(vscode.window.activeTextEditor && | ||
vscode.window.activeTextEditor.viewColumn) || | ||
vscode.ViewColumn.One; | ||
webviewManager.openDynamicPreview(resource, { | ||
resourceColumn: resourceColumn, | ||
previewColumn: previewSettings.sideBySide | ||
? vscode.ViewColumn.Beside | ||
: resourceColumn, | ||
locked: !!previewSettings.locked | ||
}); | ||
} | ||
|
||
export class ShowPreviewCommand implements Command { | ||
public readonly id = 'argdown.showPreview'; | ||
|
||
public constructor( | ||
private readonly webviewManager: ArgdownPreviewManager | ||
) { } | ||
|
||
public execute(mainUri?: vscode.Uri, allUris?: vscode.Uri[], previewSettings?: PreviewSettings) { | ||
for (const uri of Array.isArray(allUris) ? allUris : [mainUri]) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: false, | ||
locked: previewSettings && previewSettings.locked | ||
}); | ||
} | ||
} | ||
public readonly id = "argdown.showPreview"; | ||
|
||
public constructor(private readonly webviewManager: ArgdownPreviewManager) {} | ||
|
||
public execute( | ||
mainUri?: vscode.Uri, | ||
allUris?: vscode.Uri[], | ||
previewSettings?: DynamicPreviewSettings | ||
) { | ||
for (const uri of Array.isArray(allUris) ? allUris : [mainUri]) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: false, | ||
locked: previewSettings && previewSettings.locked | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export class ShowPreviewToSideCommand implements Command { | ||
public readonly id = 'argdown.showPreviewToSide'; | ||
public readonly id = "argdown.showPreviewToSide"; | ||
|
||
public constructor( | ||
private readonly webviewManager: ArgdownPreviewManager | ||
) { } | ||
public constructor(private readonly webviewManager: ArgdownPreviewManager) {} | ||
|
||
public execute(uri?: vscode.Uri, previewSettings?: PreviewSettings) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: true, | ||
locked: previewSettings && previewSettings.locked | ||
}); | ||
} | ||
public execute(uri?: vscode.Uri, previewSettings?: DynamicPreviewSettings) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: true, | ||
locked: previewSettings && previewSettings.locked | ||
}); | ||
} | ||
} | ||
|
||
|
||
export class ShowLockedPreviewToSideCommand implements Command { | ||
public readonly id = 'argdown.showLockedPreviewToSide'; | ||
public readonly id = "argdown.showLockedPreviewToSide"; | ||
|
||
public constructor( | ||
private readonly webviewManager: ArgdownPreviewManager | ||
) { } | ||
public constructor(private readonly webviewManager: ArgdownPreviewManager) {} | ||
|
||
public execute(uri?: vscode.Uri) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: true, | ||
locked: true | ||
}); | ||
} | ||
} | ||
public execute(uri?: vscode.Uri) { | ||
showPreview(this.webviewManager, uri, { | ||
sideBySide: true, | ||
locked: true | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.