Skip to content

Commit a2cd34f

Browse files
authored
Allow showTextDocument to open notebook cell URIs (microsoft#158477)
* Fix microsoft#123270 * Update to use `getCodeEditor`
1 parent 933c22a commit a2cd34f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

extensions/vscode-api-tests/src/singlefolder-tests/notebook.api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
188188
assert.strictEqual(firstNotebookEditor?.notebook, secondNotebookEditor?.notebook, 'split notebook editors share the same document');
189189
});
190190

191-
test.skip('#106657. Opening a notebook from markers view is broken ', async function () {
191+
test('#106657. Opening a notebook from markers view is broken ', async function () {
192192

193193
const document = await openRandomNotebookDocument();
194194
const [cell] = document.getCells();

src/vs/editor/browser/editorBrowser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,10 @@ export function getCodeEditor(thing: unknown): ICodeEditor | null {
12271227
return thing.getModifiedEditor();
12281228
}
12291229

1230+
if (isCompositeEditor(thing) && isCodeEditor(thing.activeCodeEditor)) {
1231+
return thing.activeCodeEditor;
1232+
}
1233+
12301234
return null;
12311235
}
12321236

src/vs/workbench/api/browser/mainThreadEditors.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ISelection } from 'vs/editor/common/core/selection';
1313
import { IDecorationOptions, IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
1414
import { ISingleEditOperation } from 'vs/editor/common/core/editOperation';
1515
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
16-
import { ITextEditorOptions, IResourceEditorInput, EditorActivation } from 'vs/platform/editor/common/editor';
16+
import { ITextEditorOptions, IResourceEditorInput, EditorActivation, EditorResolution } from 'vs/platform/editor/common/editor';
1717
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1818
import { MainThreadTextEditor } from 'vs/workbench/api/browser/mainThreadEditor';
1919
import { ExtHostContext, ExtHostEditorsShape, IApplyEditsOptions, ITextDocumentShowOptions, ITextEditorConfigurationUpdate, ITextEditorPositionData, IUndoStopOptions, MainThreadTextEditorsShape, TextEditorRevealType } from 'vs/workbench/api/common/extHost.protocol';
@@ -25,8 +25,8 @@ import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/wo
2525
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
2626
import { ILineChange } from 'vs/editor/common/diff/smartLinesDiffComputer';
2727
import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
28-
import { DEFAULT_EDITOR_ASSOCIATION, IEditorControl } from 'vs/workbench/common/editor';
29-
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
28+
import { IEditorControl } from 'vs/workbench/common/editor';
29+
import { getCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
3030
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3131

3232
export interface IMainThreadEditorLocator {
@@ -127,7 +127,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
127127
// preserve pre 1.38 behaviour to not make group active when preserveFocus: true
128128
// but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633
129129
activation: options.preserveFocus ? EditorActivation.RESTORE : undefined,
130-
override: DEFAULT_EDITOR_ASSOCIATION.id
130+
override: EditorResolution.EXCLUSIVE_ONLY
131131
};
132132

133133
const input: IResourceEditorInput = {
@@ -139,7 +139,10 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
139139
if (!editor) {
140140
return undefined;
141141
}
142-
return this._editorLocator.findTextEditorIdFor(editor);
142+
// Composite editors are made up of many editors so we return the active one at the time of opening
143+
const editorControl = editor.getControl();
144+
const codeEditor = getCodeEditor(editorControl);
145+
return codeEditor ? this._editorLocator.getIdOfCodeEditor(codeEditor) : undefined;
143146
}
144147

145148
async $tryShowEditor(id: string, position?: EditorGroupColumn): Promise<void> {

0 commit comments

Comments
 (0)