skip scroll to reveal when copying output and select the correct output

This commit is contained in:
Aaron Munger
2023-08-17 14:29:27 -07:00
parent 1f9950baef
commit bda93fcb85
6 changed files with 11 additions and 10 deletions
@@ -39,7 +39,7 @@ registerAction2(class CopyCellOutputAction extends NotebookAction {
if (mimeType?.startsWith('image/')) {
const editorService = accessor.get(IEditorService);
const editor = editorService.activeEditorPane?.getControl() as INotebookEditor;
await editor.focusNotebookCell(outputViewModel.cellViewModel as ICellViewModel, 'output');
await editor.focusNotebookCell(outputViewModel.cellViewModel as ICellViewModel, 'output', { skipReveal: true, outputId: outputViewModel.model.outputId });
editor.copyOutputImage(outputViewModel);
} else {
const clipboardService = accessor.get(IClipboardService);
@@ -151,6 +151,7 @@ export interface IFocusNotebookCellOptions {
readonly skipReveal?: boolean;
readonly focusEditorLine?: number;
readonly minimalScrolling?: boolean;
readonly outputId?: string;
}
//#endregion
@@ -2341,6 +2341,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
} else if (focusItem === 'output') {
this.focusElement(cell);
if (!this.hasEditorFocus()) {
this._list.focusView();
}
@@ -2349,9 +2350,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
return;
}
if (!options?.skipReveal) {
this._webview.focusOutput(cell.id, this._webviewFocused);
}
const focusElementId = options?.outputId ?? cell.id;
this._webview.focusOutput(focusElementId, this._webviewFocused);
cell.updateEditState(CellEditState.Preview, 'focusNotebookCell');
cell.focusMode = CellFocusMode.Output;
@@ -1606,7 +1606,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
this.webview?.focus();
}
focusOutput(cellId: string, viewFocused: boolean) {
focusOutput(cellOrOutputId: string, viewFocused: boolean) {
if (this._disposed) {
return;
}
@@ -1617,7 +1617,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
this._sendMessageToWebview({
type: 'focus-output',
cellId,
cellOrOutputId: cellOrOutputId,
});
}
@@ -273,7 +273,7 @@ export interface ICopyImageMessage {
export interface IFocusOutputMessage {
readonly type: 'focus-output';
readonly cellId: string;
readonly cellOrOutputId: string;
}
export interface IAckOutputHeight {
@@ -474,8 +474,8 @@ async function webviewPreloads(ctx: PreloadContext) {
});
};
function focusFirstFocusableOrContainerInOutput(cellId: string) {
const cellOutputContainer = document.getElementById(cellId);
function focusFirstFocusableOrContainerInOutput(cellOrOutputId: string) {
const cellOutputContainer = document.getElementById(cellOrOutputId);
if (cellOutputContainer) {
if (cellOutputContainer.contains(document.activeElement)) {
return;
@@ -1523,7 +1523,7 @@ async function webviewPreloads(ctx: PreloadContext) {
break;
}
case 'focus-output':
focusFirstFocusableOrContainerInOutput(event.data.cellId);
focusFirstFocusableOrContainerInOutput(event.data.cellOrOutputId);
break;
case 'decorations': {
let outputContainer = document.getElementById(event.data.cellId);