Skip to content

Commit d9bea7d

Browse files
committed
check if this is a diff
1 parent 88c00c5 commit d9bea7d

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

apps/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@
13921392
"@types/semver": "^7.3.13",
13931393
"@types/tmp": "^0.2.3",
13941394
"@types/uuid": "^9.0.0",
1395-
"@types/vscode": "1.66.0",
1395+
"@types/vscode": "1.94.0",
13961396
"@types/which": "^2.0.2",
13971397
"@typescript-eslint/eslint-plugin": "^5.45.0",
13981398
"@typescript-eslint/parser": "^5.45.0",

apps/vscode/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export async function activate(context: vscode.ExtensionContext) {
128128
// activate providers common to browser/node
129129
activateCommon(context, host, engine, commands);
130130

131-
132131
if (hasHooks()) {
133132
// Positron allows user to set visual or source as default mode
134133
setEditorOpener();

apps/vscode/src/providers/editor/editor.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

16-
import path, { extname } from "path";
16+
import path, { extname, win32 } from "path";
1717
import { determineMode } from "./toggle"
1818
import debounce from "lodash.debounce";
1919

@@ -58,13 +58,22 @@ import { MarkdownEngine } from "../../markdown/engine";
5858
import { lspClientTransport } from "core-node";
5959
import { editorSourceJsonRpcServer } from "editor-core";
6060
import { JsonRpcRequestTransport } from "core";
61-
import {
62-
editInSourceModeCommand,
63-
editInVisualModeCommand,
64-
reopenEditorInSourceMode
61+
import {
62+
editInSourceModeCommand,
63+
editInVisualModeCommand,
64+
reopenEditorInSourceMode
6565
} from "./toggle";
6666
import { ExtensionHost } from "../../host";
6767

68+
const labels = [
69+
"(Working Tree)",
70+
"(Deleted)",
71+
"(Theirs)",
72+
"(Ours)",
73+
"(Untracked)",
74+
"(Intent to add)",
75+
"(Type changed)"
76+
];
6877

6978
export interface QuartoVisualEditor extends QuartoEditor {
7079
hasFocus() : Promise<boolean>;
@@ -146,16 +155,21 @@ export class VisualEditorProvider implements CustomTextEditorProvider {
146155
if (!editor) {
147156
return;
148157
}
158+
149159
const document = editor.document;
150160
if (document && isQuartoDoc(document)) {
151161
const uri = document.uri.toString();
152162
// check for switch (one shot)
153163
const isSwitch = this.visualEditorPendingSwitchToSource.has(uri);
154164

165+
// check to see if this is a git diff. if so, do not try to change editor mode
166+
const tabLabel = window.tabGroups.activeTabGroup.activeTab?.label
167+
const isDiff = labels.some(label => tabLabel?.includes(label))
168+
155169
// see if user has specified visual or source mode
156170
const config = workspace.getConfiguration('quarto').get<string>('defaultEditor');
157171
const editorMode = await determineMode(document);
158-
if (editorMode && editorMode != config && !isSwitch) {
172+
if (editorMode && editorMode != config && !isSwitch && !isDiff) {
159173
const editorOpener = editorMode === 'visual' ? VisualEditorProvider.viewType : 'textEditor';
160174
await commands.executeCommand('workbench.action.closeActiveEditor');
161175
await commands.executeCommand("vscode.openWith",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,10 +2221,10 @@
22212221
resolved "https://registry.yarnpkg.com/@types/vscode-webview/-/vscode-webview-1.57.1.tgz#0bf2c9d57698b99be2bb2813272169f7f62eb714"
22222222
integrity sha512-ghW5SfuDmsGDS2A4xkvGsLwDRNc3Vj5rS6rPOyPm/IryZuf3wceZKxgYaUoW+k9f0f/CB7y2c1rRsdOWZWn0PQ==
22232223

2224-
"@types/vscode@1.66.0":
2225-
version "1.66.0"
2226-
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.66.0.tgz#e90e1308ad103f2bd31b72c17b8031b4cec0713d"
2227-
integrity sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==
2224+
"@types/vscode@1.94.0":
2225+
version "1.94.0"
2226+
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.94.0.tgz#ccd2111b6ecaba6ad4da19c2d524828fa73ae250"
2227+
integrity sha512-UyQOIUT0pb14XSqJskYnRwD2aG0QrPVefIfrW1djR+/J4KeFQ0i1+hjZoaAmeNf3Z2jleK+R2hv+EboG/m8ruw==
22282228

22292229
"@types/wcwidth@^1.0.0":
22302230
version "1.0.0"

0 commit comments

Comments
 (0)