提交 542818bf 编写于 作者: R rebornix

Fix cursor movement not revealing cell into view

上级 8c81d9a8
......@@ -622,6 +622,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
cell.state = CellState.Editing;
cell.focusMode = CellFocusMode.Editor;
this.revealInCenterIfOutsideViewport(cell);
} else {
let itemDOM = this.list?.domElementAtIndex(index);
if (document.activeElement && itemDOM && itemDOM.contains(document.activeElement)) {
......@@ -633,6 +634,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
this.list?.setFocus([index]);
this.list?.setSelection([index]);
this.revealInCenterIfOutsideViewport(cell);
this.list?.focusView();
}
}
......
......@@ -19,7 +19,6 @@ import { Range } from 'vs/editor/common/core/range';
import { CellRevealType, CellRevealPosition, CursorAtBoundary } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel';
import { EDITOR_TOP_PADDING } from 'vs/workbench/contrib/notebook/browser/constants';
export class NotebookCellList extends WorkbenchList<CellViewModel> implements IDisposable {
get onWillScroll(): Event<ScrollEvent> { return this.view.onWillScroll; }
......@@ -58,7 +57,8 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
const notebookEditorCursorAtBoundaryContext = NOTEBOOK_EDITOR_CURSOR_BOUNDARY.bindTo(contextKeyService);
notebookEditorCursorAtBoundaryContext.set('none');
let cursorSelectionLisener: IDisposable | null = null;
let cursorSelectionListener: IDisposable | null = null;
let textEditorAttachListener: IDisposable | null = null;
const recomputeContext = (element: CellViewModel) => {
switch (element.cursorAtBoundary()) {
......@@ -79,15 +79,23 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
};
// Cursor Boundary context
this._localDisposableStore.add(this.onDidChangeFocus((e) => {
cursorSelectionLisener?.dispose();
this._localDisposableStore.add(this.onDidChangeSelection((e) => {
if (e.elements.length) {
cursorSelectionListener?.dispose();
textEditorAttachListener?.dispose();
// we only validate the first focused element
const focusedElement = e.elements[0];
cursorSelectionLisener = focusedElement.onDidChangeCursorSelection(() => {
cursorSelectionListener = focusedElement.onDidChangeCursorSelection(() => {
recomputeContext(focusedElement);
});
textEditorAttachListener = focusedElement.onDidChangeEditorAttachState(() => {
if (focusedElement.editorAttached) {
recomputeContext(focusedElement);
}
});
recomputeContext(focusedElement);
return;
}
......@@ -145,7 +153,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
const startLineNumber = range.startLineNumber;
const lineOffset = element.getLineScrollTopOffset(startLineNumber);
const elementTop = this.view.elementTop(index);
const lineTop = elementTop + lineOffset + EDITOR_TOP_PADDING;
const lineTop = elementTop + lineOffset;
// TODO@rebornix 30 ---> line height * 1.5
if (lineTop < scrollTop) {
......
......@@ -57,7 +57,7 @@ export class CodeCell extends Disposable {
if (model && templateData.editor) {
templateData.editor.setModel(model);
viewCell.attachTextEditor(templateData.editor);
if (notebookEditor.getActiveCell() === viewCell) {
if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor) {
templateData.editor?.focus();
}
......@@ -81,7 +81,7 @@ export class CodeCell extends Disposable {
viewCell.editorHeight = realContentHeight;
}
if (this.notebookEditor.getActiveCell() === this.viewCell) {
if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor) {
templateData.editor?.focus();
}
}
......
......@@ -291,6 +291,10 @@ export class CellViewModel extends Disposable implements ICellViewModel {
}
if (this._textEditor === editor) {
if (this._cursorChangeListener === null) {
this._cursorChangeListener = this._textEditor.onDidChangeCursorSelection(() => this._onDidChangeCursorSelection.fire());
this._onDidChangeCursorSelection.fire();
}
return;
}
......@@ -330,6 +334,7 @@ export class CellViewModel extends Disposable implements ICellViewModel {
});
this._textEditor = undefined;
this._cursorChangeListener?.dispose();
this._cursorChangeListener = null;
this._onDidChangeEditorAttachState.fire(false);
}
......@@ -346,7 +351,7 @@ export class CellViewModel extends Disposable implements ICellViewModel {
return 0;
}
return this._textEditor.getTopForLineNumber(line);
return this._textEditor.getTopForLineNumber(line) + EDITOR_TOP_PADDING + EDITOR_TOOLBAR_HEIGHT;
}
addDecoration(decoration: model.IModelDeltaDecoration): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册