Skip to content

Commit 436de3c

Browse files
authored
fix cell editor and notebook output selection (#15384)
--------- Signed-off-by: Jonah Iden <[email protected]>
1 parent 668838d commit 436de3c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

packages/notebook/src/browser/contributions/notebook-actions-contribution.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { CellEditType, CellKind, NotebookCommand } from '../../common';
2323
import { NotebookKernelQuickPickService } from '../service/notebook-kernel-quick-pick-service';
2424
import { NotebookExecutionService } from '../service/notebook-execution-service';
2525
import { NotebookEditorWidgetService } from '../service/notebook-editor-widget-service';
26-
import { NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE, NOTEBOOK_CELL_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS } from './notebook-context-keys';
26+
import {
27+
NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE,
28+
NOTEBOOK_CELL_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_OUTPUT_FOCUSED
29+
} from './notebook-context-keys';
2730
import { NotebookClipboardService } from '../service/notebook-clipboard-service';
2831
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
2932
import { NotebookEditorWidget } from '../notebook-editor-widget';
@@ -344,17 +347,17 @@ export class NotebookActionsContribution implements CommandContribution, MenuCon
344347
{
345348
command: NotebookCommands.CUT_SELECTED_CELL.id,
346349
keybinding: 'ctrlcmd+x',
347-
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
350+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus && !${NOTEBOOK_OUTPUT_FOCUSED}`
348351
},
349352
{
350353
command: NotebookCommands.COPY_SELECTED_CELL.id,
351354
keybinding: 'ctrlcmd+c',
352-
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
355+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus && !${NOTEBOOK_OUTPUT_FOCUSED}`
353356
},
354357
{
355358
command: NotebookCommands.PASTE_CELL.id,
356359
keybinding: 'ctrlcmd+v',
357-
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
360+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus && !${NOTEBOOK_OUTPUT_FOCUSED}`
358361
},
359362
{
360363
command: NotebookCommands.NOTEBOOK_FIND.id,

packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebo
4343
import { CellOutput, NotebookCellsChangeType } from '@theia/notebook/lib/common';
4444
import { NotebookCellOutputModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-output-model';
4545
import { Deferred } from '@theia/core/lib/common/promise-util';
46+
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
47+
import { NOTEBOOK_OUTPUT_FOCUSED } from '@theia/notebook/lib/browser/contributions/notebook-context-keys';
4648

4749
export const AdditionalNotebookCellOutputCss = Symbol('AdditionalNotebookCellOutputCss');
4850

@@ -228,6 +230,9 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
228230
@inject(NotebookOptionsService)
229231
protected readonly notebookOptionsService: NotebookOptionsService;
230232

233+
@inject(ContextKeyService)
234+
protected readonly contextKeyService: ContextKeyService;
235+
231236
// returns the output Height
232237
protected readonly onDidRenderOutputEmitter = new Emitter<OutputRenderEvent>();
233238
readonly onDidRenderOutput = this.onDidRenderOutputEmitter.event;
@@ -524,6 +529,12 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
524529
this.notebook.setSelectedCell(selectedCell);
525530
}
526531
break;
532+
case 'webviewFocusChanged':
533+
if (message.focused) {
534+
window.getSelection()?.empty();
535+
}
536+
this.contextKeyService.setContext(NOTEBOOK_OUTPUT_FOCUSED, message.focused);
537+
break;
527538
case 'cellHeightRequest':
528539
const cellHeight = this.notebook.getCellByHandle(message.cellHandle)?.cellHeight ?? 0;
529540
this.webviewWidget.sendMessage({

packages/plugin-ext/src/main/browser/notebooks/renderers/output-webview-internal.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,15 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
801801
theia.postMessage({ type: 'inputFocusChanged', focused: focus } as webviewCommunication.InputFocusChange);
802802
}
803803
};
804-
805804
window.addEventListener('focusin', (event: FocusEvent) => focusChange(event, true));
806-
807805
window.addEventListener('focusout', (event: FocusEvent) => focusChange(event, false));
808806

807+
const webviewFocuseChange = (focus: boolean) => {
808+
theia.postMessage({ type: 'webviewFocusChanged', focused: focus } as webviewCommunication.WebviewFocusChange);
809+
};
810+
window.addEventListener('focus', () => webviewFocuseChange(true));
811+
window.addEventListener('blur', () => webviewFocuseChange(false));
812+
809813
new ResizeObserver(() => {
810814
theia.postMessage({
811815
type: 'bodyHeightChange',

packages/plugin-ext/src/main/browser/notebooks/renderers/webview-communication.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ export interface CellOuputFocus {
150150
readonly cellHandle: number;
151151
}
152152

153+
export interface WebviewFocusChange {
154+
readonly type: 'webviewFocusChanged';
155+
readonly focused: boolean;
156+
}
157+
153158
export interface CellHeightRequest {
154159
readonly type: 'cellHeightRequest';
155160
readonly cellHandle: number;
@@ -167,6 +172,7 @@ export type FromWebviewMessage = WebviewInitialized
167172
| KernelMessage
168173
| InputFocusChange
169174
| CellOuputFocus
175+
| WebviewFocusChange
170176
| CellHeightRequest
171177
| BodyHeightChange;
172178

0 commit comments

Comments
 (0)