Skip to content

Commit

Permalink
blur cell on shift+enter, only update cell height when changed (#14277)
Browse files Browse the repository at this point in the history
* fix cell focus on shift+enter, only update cell height when changed

Signed-off-by: Jonah Iden <[email protected]>
  • Loading branch information
jonah-iden authored Oct 10, 2024
1 parent 5058c24 commit eb5b395
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ export class NotebookCellModel implements NotebookCell, Disposable {
}

set cellHeight(height: number) {
this.onDidCellHeightChangeEmitter.fire(height);
this._cellheight = height;
if (height !== this._cellheight) {
this.onDidCellHeightChangeEmitter.fire(height);
this._cellheight = height;
}
}

@postConstruct()
Expand Down
24 changes: 13 additions & 11 deletions packages/notebook/src/browser/view/notebook-cell-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,7 @@ export class CellEditor extends React.Component<CellEditorProps, {}> {
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE, currentLine === lineCount);
}));

this.toDispose.push(this.props.cell.onWillBlurCellEditor(() => {
let parent = this.container?.parentElement;
while (parent && !parent.classList.contains('theia-notebook-cell')) {
parent = parent.parentElement;
}
if (parent) {
parent.focus();
}
}));
this.toDispose.push(this.props.cell.onWillBlurCellEditor(() => this.blurEditor()));

this.toDispose.push(this.props.cell.onDidChangeEditorOptions(options => {
this.editor?.getControl().updateOptions(options);
Expand All @@ -130,7 +122,7 @@ export class CellEditor extends React.Component<CellEditorProps, {}> {

this.toDispose.push(this.props.notebookModel.onDidChangeSelectedCell(e => {
if (e.cell !== this.props.cell && this.editor?.getControl().hasTextFocus()) {
this.props.notebookContextManager.context?.focus();
this.blurEditor();
}
}));
if (!this.props.notebookViewportService || (this.container && this.props.notebookViewportService.isElementInViewport(this.container))) {
Expand Down Expand Up @@ -231,7 +223,7 @@ export class CellEditor extends React.Component<CellEditorProps, {}> {
}));
this.props.notebookCellEditorService.editorCreated(uri, this.editor);
this.setMatches();
if (cell.editing && notebookModel.selectedCell === cell) {
if (notebookModel.selectedCell === cell) {
this.editor.getControl().focus();
}
}
Expand Down Expand Up @@ -278,4 +270,14 @@ export class CellEditor extends React.Component<CellEditorProps, {}> {
</div >;
}

protected blurEditor(): void {
let parent = this.container?.parentElement;
while (parent && !parent.classList.contains('theia-notebook-cell')) {
parent = parent.parentElement;
}
if (parent) {
parent.focus();
}
}

}

0 comments on commit eb5b395

Please sign in to comment.