Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 1x 1x 39x 39x 39x 39x 39x 12x 12x 27x 13x 13x | import { getDOMInsertPointRect } from 'roosterjs-content-model-dom';
import type { EditorCore, ImageSelection, RangeSelection } from 'roosterjs-content-model-types';
/**
* @internal
*/
export function scrollCaretIntoView(core: EditorCore, selection: RangeSelection | ImageSelection) {
const rect = getDOMInsertPointRect(
core.physicalRoot.ownerDocument,
selection.type == 'image'
? {
node: selection.image,
offset: 0,
}
: selection.isReverted
? {
node: selection.range.startContainer,
offset: selection.range.startOffset,
}
: {
node: selection.range.endContainer,
offset: selection.range.endOffset,
}
);
const visibleRect = core.api.getVisibleViewport(core);
const scrollContainer = core.domEvent.scrollContainer;
Eif (rect && visibleRect) {
if (rect.bottom > visibleRect.bottom) {
const zoomScale = core.domHelper.calculateZoomScale();
scrollContainer.scrollTop += (rect.bottom - visibleRect.bottom) / zoomScale;
} else if (rect.top < visibleRect.top) {
const zoomScale = core.domHelper.calculateZoomScale();
scrollContainer.scrollTop += (rect.top - visibleRect.top) / zoomScale;
}
}
}
|