Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-select output for focus cell container commands #209269

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
(itemDOM.ownerDocument.activeElement as HTMLElement).blur();
}

this._webview?.blurOutput();

cell.updateEditState(CellEditState.Preview, 'focusNotebookCell');
cell.focusMode = CellFocusMode.Container;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,16 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
});
}

blurOutput() {
if (this._disposed) {
return;
}

this._sendMessageToWebview({
type: 'blur-output'
});
}

async find(query: string, options: { wholeWord?: boolean; caseSensitive?: boolean; includeMarkup: boolean; includeOutput: boolean; shouldGetSearchPreviewInfo: boolean; ownerID: string }): Promise<IFindMatch[]> {
if (query === '') {
this._sendMessageToWebview({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface IScrollAckMessage extends BaseToWebviewMessage {
readonly version: number;
}

export interface IBlurOutputMessage extends BaseToWebviewMessage {
export interface IFocusEditorMessage extends BaseToWebviewMessage {
readonly type: 'focus-editor';
readonly cellId: string;
readonly focusNext?: boolean;
Expand Down Expand Up @@ -262,6 +262,10 @@ export interface IFocusOutputMessage {
readonly alternateId?: string;
}

export interface IBlurOutputMessage {
readonly type: 'blur-output';
}

export interface IAckOutputHeight {
readonly cellId: string;
readonly outputId: string;
Expand Down Expand Up @@ -494,7 +498,7 @@ export type FromWebviewMessage = WebviewInitialized |
IScrollToRevealMessage |
IWheelMessage |
IScrollAckMessage |
IBlurOutputMessage |
IFocusEditorMessage |
ICustomKernelMessage |
ICustomRendererMessage |
IClickedDataUrlMessage |
Expand All @@ -520,6 +524,7 @@ export type FromWebviewMessage = WebviewInitialized |

export type ToWebviewMessage = IClearMessage |
IFocusOutputMessage |
IBlurOutputMessage |
IAckOutputHeightMessage |
ICreationRequestMessage |
IViewScrollTopRequestMessage |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ async function webviewPreloads(ctx: PreloadContext) {
postNotebookMessage<webviewMessages.IOutputFocusMessage>('outputFocus', outputFocus);
}
};

const blurOutput = () => {
const selection = window.getSelection();
if (!selection) {
return;
}
selection.removeAllRanges();
};

const selectOutputContents = (cellOrOutputId: string) => {
const selection = window.getSelection();
if (!selection) {
Expand Down Expand Up @@ -689,7 +698,7 @@ async function webviewPreloads(ctx: PreloadContext) {
element.id = `focus-sink-${cellId}`;
element.tabIndex = 0;
element.addEventListener('focus', () => {
postNotebookMessage<webviewMessages.IBlurOutputMessage>('focus-editor', {
postNotebookMessage<webviewMessages.IFocusEditorMessage>('focus-editor', {
cellId: cellId,
focusNext
});
Expand Down Expand Up @@ -1732,6 +1741,9 @@ async function webviewPreloads(ctx: PreloadContext) {
case 'focus-output':
focusFirstFocusableOrContainerInOutput(event.data.cellOrOutputId, event.data.alternateId);
break;
case 'blur-output':
blurOutput();
break;
case 'select-output-contents':
selectOutputContents(event.data.cellOrOutputId);
break;
Expand Down
Loading