提交 b5473f5a 编写于 作者: R rebornix

reveal cell into view.

上级 4de61f3d
......@@ -30,7 +30,7 @@ export class NotebookFindWidget extends SimpleFindWidget {
protected onInputChanged(): boolean {
const val = this.inputValue;
if (val) {
this._findMatches = this._notebookEditor.startFind(val);
this._findMatches = this._notebookEditor.startFind(val).filter(match => match.matches.length > 0);
if (this._findMatches.length) {
this._currentMatch = this._findMatches[0];
this.set(this._findMatches);
......
......@@ -32,6 +32,9 @@ export interface INotebookEditor {
getFontInfo(): BareFontInfo | undefined;
getListDimension(): DOM.Dimension | null;
getOutputRenderer(): OutputRenderer;
revealInView(cell: CellViewModel, offset?: number): void;
revealInCenter(cell: CellViewModel, offset?: number): void;
revealInCenterIfOutsideViewport(cell: CellViewModel, offset?: number): void;
changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
}
......
......@@ -158,7 +158,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor, Noteb
get viewType() { return this.notebookViewModel?.viewType; }
//#region Editor
//#region Editor Core
public get isNotebookEditor() {
......@@ -407,7 +407,31 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor, Noteb
//#endregion
//#region Decorations
//#region Editor Features
revealInView(cell: CellViewModel, offset?: number) {
const index = this.notebookViewModel?.getViewCellIndex(cell);
if (index !== undefined) {
this.list?.revealInView(index, offset);
}
}
revealInCenterIfOutsideViewport(cell: CellViewModel, offset?: number) {
const index = this.notebookViewModel?.getViewCellIndex(cell);
if (index !== undefined) {
this.list?.revealInCenterIfOutsideViewport(index, offset);
}
}
revealInCenter(cell: CellViewModel, offset?: number) {
const index = this.notebookViewModel?.getViewCellIndex(cell);
if (index !== undefined) {
this.list?.revealInCenter(index, offset);
}
}
changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
return this.notebookViewModel?.changeDecorations(callback);
......@@ -435,7 +459,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor, Noteb
let cell = match.cell;
let index = this.notebookViewModel!.viewCells.indexOf(cell);
this.list?.reveal(index);
this.list?.revealInView(index);
}
public showFind() {
......@@ -489,7 +513,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor, Noteb
}
DOM.scheduleAtNextAnimationFrame(() => {
this.list?.reveal(insertIndex, 0.33);
this.list?.revealInCenterIfOutsideViewport(insertIndex);
});
}
......
......@@ -14,6 +14,7 @@ import { IListService, IWorkbenchListOptions, WorkbenchList } from 'vs/platform/
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { isMacintosh } from 'vs/base/common/platform';
import { isNumber } from 'vs/base/common/types';
export class NotebookCellList<T> extends WorkbenchList<T> {
get onWillScroll(): Event<ScrollEvent> { return this.view.onWillScroll; }
......@@ -76,6 +77,36 @@ export class NotebookCellList<T> extends WorkbenchList<T> {
super.domFocus();
}
revealInView(index: number, offset?: number) {
const scrollTop = this.view.getScrollTop();
const wrapperBottom = scrollTop + this.view.renderHeight;
const elementTop = this.view.elementTop(index);
const viewItemOffset = elementTop + (isNumber(offset) ? offset : 0);
if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) {
this.view.setScrollTop(viewItemOffset);
}
}
revealInCenterIfOutsideViewport(index: number, offset?: number) {
const scrollTop = this.view.getScrollTop();
const wrapperBottom = scrollTop + this.view.renderHeight;
const elementTop = this.view.elementTop(index);
const viewItemOffset = elementTop + (isNumber(offset) ? offset : 0);
if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) {
this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2);
}
}
revealInCenter(index: number, offset?: number) {
const elementTop = this.view.elementTop(index);
const viewItemOffset = elementTop + (isNumber(offset) ? offset : 0);
this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2);
}
}
function isContextMenuFocused() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册