re #123828. Reveal middle of the cell to the center.

This commit is contained in:
rebornix
2022-03-28 11:23:23 -07:00
parent cf321f8c83
commit fd7f35aa4c
@@ -1252,8 +1252,20 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
this.view.setScrollTop(this.view.elementTop(viewIndex));
break;
case CellRevealPosition.Center:
this.view.setScrollTop(elementTop - this.view.renderHeight / 2);
this.view.setScrollTop(this.view.elementTop(viewIndex) - this.view.renderHeight / 2);
{
// reveal the cell top in the viewport center initially
this.view.setScrollTop(elementTop - this.view.renderHeight / 2);
// cell rendered already, we now have a more accurate cell height
const newElementTop = this.view.elementTop(viewIndex);
const newElementHeight = this.view.elementHeight(viewIndex);
const renderHeight = this.getViewScrollBottom() - this.getViewScrollTop();
if (newElementHeight >= renderHeight) {
// cell is larger than viewport, reveal top
this.view.setScrollTop(newElementTop);
} else {
this.view.setScrollTop(newElementTop + (newElementHeight / 2) - (renderHeight / 2));
}
}
break;
case CellRevealPosition.Bottom:
this.view.setScrollTop(this.scrollTop + (elementBottom - wrapperBottom));