|
14 | 14 | */ |
15 | 15 | import * as vscode from "vscode"; |
16 | 16 | import { commands, window, workspace, TextDocument, ViewColumn } from "vscode"; |
17 | | -import { Command } from "../../core/command"; |
18 | | -import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc"; |
| 17 | +import * as path from 'path'; |
19 | 18 | import * as quarto from "quarto-core"; |
20 | 19 | import fs from "node:fs"; |
21 | | -import * as path from 'path'; |
22 | 20 | import yaml from "js-yaml"; |
| 21 | +import { Command } from "../../core/command"; |
| 22 | +import { isQuartoDoc, kQuartoLanguageId } from "../../core/doc"; |
23 | 23 | import { VisualEditorProvider } from "./editor"; |
24 | 24 |
|
25 | 25 |
|
26 | | -export async function determineMode(doc: TextDocument, config: string | undefined): Promise<boolean> { |
27 | | - const text = doc.getText() |
28 | | - |
| 26 | +export async function determineMode(doc: string): Promise<string | undefined> { |
29 | 27 | let editorOpener = undefined; |
30 | 28 |
|
31 | 29 | // check if file itself has a mode |
32 | | - if (hasEditorMode(text, "source")) { |
| 30 | + if (hasEditorMode(doc, "source")) { |
33 | 31 | editorOpener = "source"; |
34 | 32 | } |
35 | | - else if (hasEditorMode(text, "visual")) { |
| 33 | + else if (hasEditorMode(doc, "visual")) { |
36 | 34 | editorOpener = "visual"; |
37 | 35 | } |
38 | 36 | // check if has a _quarto.yml or _quarto.yaml file with editor specified |
39 | 37 | else { |
40 | 38 | editorOpener = workspaceHasQuartoYaml(); |
41 | 39 | } |
42 | | - if (editorOpener && editorOpener != config) { |
43 | | - editorOpener = editorOpener === 'visual' ? VisualEditorProvider.viewType : 'textEditor'; |
44 | | - await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); |
45 | | - await vscode.commands.executeCommand("vscode.openWith", |
46 | | - doc.uri, |
47 | | - editorOpener |
48 | | - ); |
49 | | - return true; |
50 | | - } |
51 | 40 |
|
52 | | - return false; |
| 41 | + return editorOpener; |
53 | 42 | } |
54 | 43 |
|
55 | 44 | export async function setEditorOpener() { |
|
0 commit comments