Skip to content

Commit

Permalink
fix(argdown-vscode): fixes resource paths,
Browse files Browse the repository at this point in the history
updates preview code
based on changes in VSCode's
Markdown preview
  • Loading branch information
christianvoigt committed Feb 21, 2022
1 parent 8a1be2d commit 79818c3
Show file tree
Hide file tree
Showing 20 changed files with 1,802 additions and 987 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"endOfLine": "lf"
"endOfLine": "lf"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Argdown logo](./argdown-arrow.png?raw=true "Argdown logo")

**v1.8.0 released! Check out [the new features](https://argdown.org/changes/)**
**v1.8.2 released! Check out [the new features](https://argdown.org/changes/)**

[Argdown](https://christianvoigt.github.io/argdown) is a simple syntax for analyzing complex argumentation.

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ actionLink: /guide/
footer: MIT Licensed | Copyright © 2018-present Christian Voigt | Funded by Debatelab, KIT Karlsuhe
---

<p class="latest-news">January 2022: v1.8.0 has been released (<a href="/changes">changelog</a>)</p>
<p class="latest-news">February 2022: v1.8.2 has been released (<a href="/changes">changelog</a>)</p>
<div class="features">
<div class="feature">
<h2>Simple</h2>
Expand Down
7 changes: 7 additions & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ This release adds [web extension support](https://code.visualstudio.com/blogs/20
### v1.8.1

- fixes paths for webview resources

### v1.8.2

only affects argdown-vscode:

- fixes paths again for electron
- updates complete codebase of Argdown preview to reflect changes in original VSCode Markdown preview
4 changes: 2 additions & 2 deletions packages/argdown-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "media/argdown-mark-blue-256x256.png",
"author": "Christian Voigt",
"license": "MIT",
"version": "1.8.1",
"version": "1.8.2",
"publisher": "christianvoigt",
"homepage": "https://argdown.org",
"repository": {
Expand Down Expand Up @@ -559,7 +559,7 @@
"@types/node": "^17.0.0",
"@types/vscode": "^1.63.1",
"@vscode/test-electron": "^2.0.3",
"@vscode/test-web": "^0.0.15",
"@vscode/test-web": "^0.0.22",
"babel-loader": "8.2.3",
"brfs": "^2.0.2",
"crypto-browserify": "^3.12.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/argdown-vscode/src/browser-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
ExtensionContentSecurityPolicyArbiter,
PreviewSecuritySelector
} from "./preview/security";
import { ArgdownExtensionContributions } from "./preview/ArgdownExtensionContributions";
import { ArgdownContentProvider } from "./preview/ArgdownContentProvider";
import { ArgdownPreviewManager } from "./preview/ArgdownPreviewManager";
import { CommandManager } from "./commands/CommandManager";
import * as commands from "./commands/index";
import { getArgdownExtensionContributions } from "./preview/ArgdownExtensions";

let client: LanguageClient;

Expand All @@ -28,7 +28,7 @@ export function activate(context: ExtensionContext) {
context.globalState,
context.workspaceState
);
const contributions = new ArgdownExtensionContributions();
const contributions = getArgdownExtensionContributions(context);
const contentProvider = new ArgdownContentProvider(
argdownEngine,
context,
Expand Down
171 changes: 74 additions & 97 deletions packages/argdown-vscode/src/commands/showPreview.ts
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
});
}
}
4 changes: 2 additions & 2 deletions packages/argdown-vscode/src/node-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
ExtensionContentSecurityPolicyArbiter,
PreviewSecuritySelector
} from "./preview/security";
import { ArgdownExtensionContributions } from "./preview/ArgdownExtensionContributions";
import createArgdownMarkdownItPlugin from "@argdown/markdown-it-plugin";
import { nodeConfigLoader } from "./nodeConfigLoader";
import { getArgdownExtensionContributions } from "./preview/ArgdownExtensions";
// import { ForkOptions } from "vscode-languageclient/lib/client";

let client: LanguageClient;
Expand All @@ -36,7 +36,7 @@ export function activate(context: vscode.ExtensionContext) {
context.globalState,
context.workspaceState
);
const contributions = new ArgdownExtensionContributions();
const contributions = getArgdownExtensionContributions(context);
const contentProvider = new ArgdownContentProvider(
argdownEngine,
context,
Expand Down
Loading

0 comments on commit 79818c3

Please sign in to comment.