Skip to content

Commit

Permalink
0.3.13 (#203)
Browse files Browse the repository at this point in the history
* Try to fix isseu #202

* Try to support #198

* Add mathRenderingOnlineService setting

* Add/Change "openPreview" and "openPreviewToTheSide" commands.

* Upgrade mume to 0.3.8
  • Loading branch information
shd101wyy authored Mar 18, 2019
1 parent 4cd35b0 commit e6bb065
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Contact me if you are willing to help translate the documentation :)
| Shortcuts | Functionality |
| ------------------------------------------- | -------------------------- |
| <kbd>cmd-k v</kbd> | Open preview |
| <kbd>cmd-k v</kbd> | Open preview to the Side |
| <kbd>ctrl-shift-v</kbd> | Open preview |
| <kbd>ctrl-shift-s</kbd> | Sync preview / Sync source |
| <kbd>shift-enter</kbd> | Run Code Chunk |
| <kbd>ctrl-shift-enter</kbd> | Run all Code Chunks |
Expand Down
27 changes: 21 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
],
"activationEvents": [
"onLanguage:markdown",
"onCommand:markdown-preview-enhanced.openPreview"
"onCommand:markdown-preview-enhanced.openPreviewToTheSide"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "markdown-preview-enhanced.openPreviewToTheSide",
"title": "Markdown Preview Enhanced: Open Preview to the Side",
"category": "Markdown",
"icon": {
"light": "./media/PreviewOnRightPane_16x.svg",
"dark": "./media/PreviewOnRightPane_16x_dark.svg"
}
},
{
"command": "markdown-preview-enhanced.openPreview",
"title": "Markdown Preview Enhanced: Open Preview",
Expand Down Expand Up @@ -105,11 +114,17 @@
],
"keybindings": [
{
"command": "markdown-preview-enhanced.openPreview",
"command": "markdown-preview-enhanced.openPreviewToTheSide",
"key": "ctrl+k v",
"mac": "cmd+k v",
"when": "editorLangId == markdown"
},
{
"command": "markdown-preview-enhanced.openPreview",
"key": "ctrl+shift+v",
"mac": "cmd+shift+v",
"when": "editorLangId == markdown"
},
{
"command": "markdown-preview-enhanced.runAllCodeChunks",
"key": "ctrl+shift+enter",
Expand All @@ -129,14 +144,14 @@
"menus": {
"editor/context": [
{
"command": "markdown-preview-enhanced.openPreview",
"command": "markdown-preview-enhanced.openPreviewToTheSide",
"when": "editorLangId == markdown",
"group": "markdown-preview-enhanced"
}
],
"editor/title": [
{
"command": "markdown-preview-enhanced.openPreview",
"command": "markdown-preview-enhanced.openPreviewToTheSide",
"when": "editorLangId == markdown",
"group": "navigation"
}
Expand Down Expand Up @@ -219,7 +234,7 @@
],
"type": "array"
},
"markdown-preview-enhanced.saveAsMarkdown.mathRenderingOnLineService": {
"markdown-preview-enhanced.mathRenderingOnlineService": {
"description": "Choose the Math expression rendering method option for GFM markdown export (Save as Markdown).",
"default": "https://latex.codecogs.com/gif.latex",
"type": "string",
Expand Down Expand Up @@ -439,7 +454,7 @@
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"dependencies": {
"@shd101wyy/mume": "^0.3.7",
"@shd101wyy/mume": "^0.3.8",
"@types/vfile": "^3.0.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class MarkdownPreviewEnhancedConfig implements MarkdownEngineConfig {
public readonly mathRenderingOption: MathRenderingOption;
public readonly mathInlineDelimiters: string[][];
public readonly mathBlockDelimiters: string[][];
public readonly mathRenderingOnLineService: string;
public readonly mathRenderingOnlineService: string;
public readonly codeBlockTheme: string;
public readonly mermaidTheme: string;
public readonly previewTheme: string;
Expand Down Expand Up @@ -69,8 +69,8 @@ export class MarkdownPreviewEnhancedConfig implements MarkdownEngineConfig {
) as MathRenderingOption;
this.mathInlineDelimiters = config.get<string[][]>("mathInlineDelimiters");
this.mathBlockDelimiters = config.get<string[][]>("mathBlockDelimiters");
this.mathRenderingOnLineService = config.get<string>(
"saveAsMarkdown.mathRenderingOnLineService",
this.mathRenderingOnlineService = config.get<string>(
"mathRenderingOnlineService",
);
this.codeBlockTheme = config.get<string>("codeBlockTheme");
this.previewTheme = config.get<string>("previewTheme");
Expand Down
31 changes: 29 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export function activate(context: vscode.ExtensionContext) {
// assume only one preview supported.
const contentProvider = new MarkdownPreviewEnhancedView(context);

function openPreviewToTheSide(uri?: vscode.Uri) {
let resource = uri;
if (!(resource instanceof vscode.Uri)) {
if (vscode.window.activeTextEditor) {
// we are relaxed and don't check for markdown files
resource = vscode.window.activeTextEditor.document.uri;
}
}
contentProvider.initPreview(resource, vscode.window.activeTextEditor, {
viewColumn: vscode.ViewColumn.Two,
preserveFocus: true,
});
}

function openPreview(uri?: vscode.Uri) {
let resource = uri;
if (!(resource instanceof vscode.Uri)) {
Expand All @@ -28,7 +42,10 @@ export function activate(context: vscode.ExtensionContext) {
resource = vscode.window.activeTextEditor.document.uri;
}
}
contentProvider.initPreview(resource, vscode.window.activeTextEditor);
contentProvider.initPreview(resource, vscode.window.activeTextEditor, {
viewColumn: vscode.ViewColumn.One,
preserveFocus: false,
});
}

function toggleScrollSync() {
Expand Down Expand Up @@ -500,7 +517,10 @@ export function activate(context: vscode.ExtensionContext) {
isUsingSinglePreview &&
!contentProvider.previewHasTheSameSingleSourceUri(sourceUri)
) {
contentProvider.initPreview(sourceUri, textEditor);
contentProvider.initPreview(sourceUri, textEditor, {
viewColumn: contentProvider.getPreview(sourceUri).viewColumn,
preserveFocus: true,
});
} else if (
!isUsingSinglePreview &&
automaticallyShowPreviewOfMarkdownBeingEdited
Expand Down Expand Up @@ -528,6 +548,13 @@ export function activate(context: vscode.ExtensionContext) {
}))
*/

context.subscriptions.push(
vscode.commands.registerCommand(
"markdown-preview-enhanced.openPreviewToTheSide",
openPreviewToTheSide,
),
);

context.subscriptions.push(
vscode.commands.registerCommand(
"markdown-preview-enhanced.openPreview",
Expand Down
41 changes: 32 additions & 9 deletions src/preview-content-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export class MarkdownPreviewEnhancedView {
if (useSinglePreview()) {
this.singlePreviewPanel = null;
this.singlePreviewPanelSourceUriTarget = null;
return (this.previewMaps = {});
this.preview2EditorMap = new Map();
this.previewMaps = {};
} else {
const previewPanel = this.getPreview(sourceUri);
if (previewPanel) {
Expand Down Expand Up @@ -323,12 +324,31 @@ export class MarkdownPreviewEnhancedView {
return engine;
}

public async initPreview(sourceUri: vscode.Uri, editor: vscode.TextEditor) {
public async initPreview(
sourceUri: vscode.Uri,
editor: vscode.TextEditor,
viewOptions: { viewColumn: vscode.ViewColumn; preserveFocus?: boolean },
) {
const isUsingSinglePreview = useSinglePreview();
let previewPanel: vscode.WebviewPanel;
if (isUsingSinglePreview && this.singlePreviewPanel) {
previewPanel = this.singlePreviewPanel;
this.singlePreviewPanelSourceUriTarget = sourceUri;
const oldResourceRoot =
this.getProjectDirectoryPath(
this.singlePreviewPanelSourceUriTarget,
vscode.workspace.workspaceFolders,
) || path.dirname(this.singlePreviewPanelSourceUriTarget.fsPath);
const newResourceRoot =
this.getProjectDirectoryPath(
sourceUri,
vscode.workspace.workspaceFolders,
) || path.dirname(sourceUri.fsPath);
if (oldResourceRoot !== newResourceRoot) {
this.singlePreviewPanel.dispose();
return this.initPreview(sourceUri, editor, viewOptions);
} else {
previewPanel = this.singlePreviewPanel;
this.singlePreviewPanelSourceUriTarget = sourceUri;
}
} else if (this.previewMaps[sourceUri.fsPath]) {
previewPanel = this.previewMaps[sourceUri.fsPath];
} else {
Expand All @@ -341,14 +361,14 @@ export class MarkdownPreviewEnhancedView {
this.getProjectDirectoryPath(
sourceUri,
vscode.workspace.workspaceFolders,
),
) || path.dirname(sourceUri.fsPath),
),
];

previewPanel = vscode.window.createWebviewPanel(
"markdown-preview-enhanced",
`Preview ${path.basename(sourceUri.fsPath)}`,
{ viewColumn: vscode.ViewColumn.Two, preserveFocus: true },
viewOptions,
{
enableFindWidget: true,
localResourceRoots,
Expand Down Expand Up @@ -487,7 +507,7 @@ export class MarkdownPreviewEnhancedView {
// not presentation mode
vscode.workspace.openTextDocument(sourceUri).then((document) => {
const text = document.getText();
previewPanel.webview.postMessage({
this.previewPostMessage(sourceUri, {
command: "startParsingMarkdown",
});

Expand All @@ -510,7 +530,7 @@ export class MarkdownPreviewEnhancedView {
// restart iframe
this.refreshPreview(sourceUri);
} else {
previewPanel.webview.postMessage({
this.previewPostMessage(sourceUri, {
command: "updateHTML",
html,
tocHTML,
Expand All @@ -534,7 +554,10 @@ export class MarkdownPreviewEnhancedView {
editor.document.uri &&
editor.document.uri.fsPath === sourceUri.fsPath
) {
this.initPreview(sourceUri, editor);
this.initPreview(sourceUri, editor, {
viewColumn: previewPanel.viewColumn,
preserveFocus: true,
});
}
});
}
Expand Down

0 comments on commit e6bb065

Please sign in to comment.