提交 589b5237 编写于 作者: R rebornix

Scroll cell into view major update:

We change `scrollTop` to scroll cells into view, but cell's position
is based on template height, which is not correct. Markdown cells
are dynamic, so after we scroll cells into view, they will change
their real height, thus we need to set `scrollTop` again to adjust
the position again.

For code cell, they will call `updateElementHeight` to change its
size. It should pass in `focusedElement` as the anchor element,
then the focused element will keep its visual position.
上级 508dead0
......@@ -261,7 +261,14 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
const element = this.view.element(index);
if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) {
// let it render
this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2);
// after rendering, it might be pushed down due to markdown cell dynamic height
const elementTop = this.view.elementTop(index);
this.view.setScrollTop(elementTop - this.view.renderHeight / 2);
// reveal editor
if (!element.editorAttached) {
getEditorAttachedPromise(element).then(() => reveal(index, range, revealType));
} else {
......@@ -295,15 +302,14 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
return;
}
let viewItemOffset = elementTop;
if (revealPosition === CellRevealPosition.Top) {
viewItemOffset = elementTop;
} else if (revealPosition === CellRevealPosition.Center) {
viewItemOffset = elementTop - this.view.renderHeight / 2;
}
// first render
const viewItemOffset = revealPosition === CellRevealPosition.Top ? elementTop : (elementTop - this.view.renderHeight / 2);
this.view.setScrollTop(viewItemOffset);
// second scroll as markdown cell is dynamic
const newElementTop = this.view.elementTop(index);
const newViewItemOffset = revealPosition === CellRevealPosition.Top ? newElementTop : (newElementTop - this.view.renderHeight / 2);
this.view.setScrollTop(newViewItemOffset);
}
revealInView(index: number) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册