Skip to content

Commit 587ce36

Browse files
committed
move function to helper file
1 parent db6c9a9 commit 587ce36

File tree

2 files changed

+71
-67
lines changed

2 files changed

+71
-67
lines changed

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { ILabelService } from 'vs/platform/label/common/label';
5757
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
5858
import { NotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl';
5959
import { INotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService';
60-
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
6160

6261
// Editor Controller
6362
import 'vs/workbench/contrib/notebook/browser/controller/coreActions';
@@ -115,8 +114,8 @@ import { NotebookLoggingService } from 'vs/workbench/contrib/notebook/browser/se
115114
import product from 'vs/platform/product/common/product';
116115
import { AccessibilityHelpAction, AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
117116
import { NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
118-
import { runAccessibilityHelpAction } from 'vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp';
119-
import { AccessibleViewType, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
117+
import { runAccessibilityHelpAction, showAccessibleOutput } from 'vs/workbench/contrib/notebook/browser/notebookAccessibility';
118+
import { IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
120119

121120
/*--------------------------------------------------------------------------------------------- */
122121

@@ -697,75 +696,13 @@ class NotebookAccessibleViewContribution extends Disposable {
697696
super();
698697
this._register(AccessibleViewAction.addImplementation(100, 'notebook', accessor => {
699698
const accessibleViewService = accessor.get(IAccessibleViewService);
699+
const editorService = accessor.get(IEditorService);
700700

701-
const activePane = accessor.get(IEditorService).activeEditorPane;
702-
const notebookEditor = getNotebookEditorFromEditorPane(activePane);
703-
const notebookViewModel = notebookEditor?.getViewModel();
704-
const selections = notebookViewModel?.getSelections();
705-
notebookViewModel?.getCellIndex;
706-
const notebookDocument = notebookViewModel?.notebookDocument;
707-
708-
if (!selections || !notebookDocument || !notebookEditor?.textModel) {
709-
return false;
710-
}
711-
712-
const viewCell = notebookViewModel.viewCells[selections[0].start];
713-
let outputContent = '';
714-
const decoder = new TextDecoder();
715-
for (let i = 0; i < viewCell.outputsViewModels.length; i++) {
716-
const outputViewModel = viewCell.outputsViewModels[i];
717-
const outputTextModel = viewCell.model.outputs[i];
718-
const [mimeTypes, pick] = outputViewModel.resolveMimeTypes(notebookEditor.textModel, undefined);
719-
const mimeType = mimeTypes[pick].mimeType;
720-
let buffer = outputTextModel.outputs.find(output => output.mime === mimeType);
721-
722-
if (!buffer || mimeType.startsWith('image')) {
723-
buffer = outputTextModel.outputs.find(output => !output.mime.startsWith('image'));
724-
}
725-
726-
let text = `${mimeType}`; // default in case we can't get the text value for some reason.
727-
if (buffer) {
728-
const charLimit = 100_000;
729-
text = decoder.decode(buffer.data.slice(0, charLimit).buffer);
730-
731-
if (buffer.data.byteLength > charLimit) {
732-
text = text + '...(truncated)';
733-
}
734-
735-
if (mimeType.endsWith('error')) {
736-
text = text.replace(/\\u001b\[[0-9;]*m/gi, '').replaceAll('\\n', '\n');
737-
}
738-
}
739-
740-
const index = viewCell.outputsViewModels.length > 1
741-
? `Cell output ${i + 1} of ${viewCell.outputsViewModels.length}\n`
742-
: '';
743-
outputContent = outputContent.concat(`${index}${text}\n`);
744-
}
745-
746-
if (!outputContent) {
747-
return false;
748-
}
749-
750-
accessibleViewService.show({
751-
verbositySettingKey: 'notebook',
752-
provideContent(): string { return outputContent; },
753-
onClose() {
754-
notebookEditor?.setFocus(selections[0]);
755-
activePane?.focus();
756-
},
757-
options: {
758-
ariaLabel: nls.localize('NotebookCellOutputAccessibleView', "Notebook Cell Output Accessible View"),
759-
language: 'plaintext',
760-
type: AccessibleViewType.View
761-
}
762-
});
763-
return true;
701+
return showAccessibleOutput(accessibleViewService, editorService);
764702
}, NOTEBOOK_OUTPUT_FOCUSED));
765703
}
766704
}
767705

768-
769706
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
770707
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookContribution, LifecyclePhase.Starting);
771708
workbenchContributionsRegistry.registerWorkbenchContribution(CellContentProvider, LifecyclePhase.Starting);

src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.ts renamed to src/vs/workbench/contrib/notebook/browser/notebookAccessibility.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1010
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
1111
import { AccessibleViewType, IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
1212
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
13+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
14+
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1315

1416
export function getAccessibilityHelpText(accessor: ServicesAccessor): string {
1517
const keybindingService = accessor.get(IKeybindingService);
@@ -55,3 +57,68 @@ export async function runAccessibilityHelpAction(accessor: ServicesAccessor, edi
5557
options: { type: AccessibleViewType.HelpMenu, ariaLabel: 'Notebook accessibility help' }
5658
});
5759
}
60+
61+
export function showAccessibleOutput(accessibleViewService: IAccessibleViewService, editorService: IEditorService) {
62+
const activePane = editorService.activeEditorPane;
63+
const notebookEditor = getNotebookEditorFromEditorPane(activePane);
64+
const notebookViewModel = notebookEditor?.getViewModel();
65+
const selections = notebookViewModel?.getSelections();
66+
const notebookDocument = notebookViewModel?.notebookDocument;
67+
68+
if (!selections || !notebookDocument || !notebookEditor?.textModel) {
69+
return false;
70+
}
71+
72+
const viewCell = notebookViewModel.viewCells[selections[0].start];
73+
let outputContent = '';
74+
const decoder = new TextDecoder();
75+
for (let i = 0; i < viewCell.outputsViewModels.length; i++) {
76+
const outputViewModel = viewCell.outputsViewModels[i];
77+
const outputTextModel = viewCell.model.outputs[i];
78+
const [mimeTypes, pick] = outputViewModel.resolveMimeTypes(notebookEditor.textModel, undefined);
79+
const mimeType = mimeTypes[pick].mimeType;
80+
let buffer = outputTextModel.outputs.find(output => output.mime === mimeType);
81+
82+
if (!buffer || mimeType.startsWith('image')) {
83+
buffer = outputTextModel.outputs.find(output => !output.mime.startsWith('image'));
84+
}
85+
86+
let text = `${mimeType}`; // default in case we can't get the text value for some reason.
87+
if (buffer) {
88+
const charLimit = 100_000;
89+
text = decoder.decode(buffer.data.slice(0, charLimit).buffer);
90+
91+
if (buffer.data.byteLength > charLimit) {
92+
text = text + '...(truncated)';
93+
}
94+
95+
if (mimeType.endsWith('error')) {
96+
text = text.replace(/\\u001b\[[0-9;]*m/gi, '').replaceAll('\\n', '\n');
97+
}
98+
}
99+
100+
const index = viewCell.outputsViewModels.length > 1
101+
? `Cell output ${i + 1} of ${viewCell.outputsViewModels.length}\n`
102+
: '';
103+
outputContent = outputContent.concat(`${index}${text}\n`);
104+
}
105+
106+
if (!outputContent) {
107+
return false;
108+
}
109+
110+
accessibleViewService.show({
111+
verbositySettingKey: AccessibilityVerbositySettingId.Notebook,
112+
provideContent(): string { return outputContent; },
113+
onClose() {
114+
notebookEditor?.setFocus(selections[0]);
115+
activePane?.focus();
116+
},
117+
options: {
118+
ariaLabel: localize('NotebookCellOutputAccessibleView', "Notebook Cell Output Accessible View"),
119+
language: 'plaintext',
120+
type: AccessibleViewType.View
121+
}
122+
});
123+
return true;
124+
}

0 commit comments

Comments
 (0)