UNPKG

devexpress-richedit

Version:

DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.

41 lines (40 loc) 2.33 kB
import { MixedSize } from '../../../common/utils/mixed-size'; import { GoToPageCommandBase } from './go-to-page-command-base'; export class GoToNextPageCommandBase extends GoToPageCommandBase { goToPage(layoutPosition, x, y) { const visibleAreaHeight = MixedSize.fromUI(this.control.viewManager.sizes.getVisibleAreaHeight(false)).useScale(this.scale); const viewportHeight = MixedSize.fromLayout(Math.max(layoutPosition.row.height, visibleAreaHeight.LayoutSize)).useScale(this.scale); const viewportBottom = MixedSize.fromUI(this.control.viewManager.canvas.scrollTop).useScale(this.scale).addSize(viewportHeight); let page = layoutPosition.page; const pageIndex = this.findPageIndexByOffsetY(viewportBottom.LayoutSize); this.scrollToPosition(pageIndex, viewportBottom.LayoutSize); const newY = MixedSize.add(MixedSize.fromLayout(y).useScale(this.scale), viewportHeight); const position = this.getPosition(page, MixedSize.fromLayout(x).useScale(this.scale), newY, viewportBottom, viewportHeight); this.changeSelection(position); } getPosition(currentPage, x, y, viewportTop, viewportHeight) { const currentPageY = this.control.viewManager.sizes.getPageOffsetY(currentPage); const newAbsoluteY = MixedSize.max(y.addLayoutSize(currentPageY), viewportTop); let pageIndex = this.findPageIndexByOffsetY(newAbsoluteY.LayoutSize); const pageY = this.getPageOffsetY(pageIndex); const htr = this.calculateHitTestResult(pageIndex, x.LayoutSize, newAbsoluteY.LayoutSize - pageY); const rowY = htr.getLayoutY() + pageY + htr.row.height / 2; if (rowY > viewportTop.LayoutSize) return htr.getPosition(); const viewportBottom = MixedSize.add(viewportTop, viewportHeight); const position = this.tryFindVisiblePosition(x.LayoutSize, newAbsoluteY.LayoutSize, viewportBottom.LayoutSize); if (position !== null) return position; return htr.getPosition(); } } export class GoToNextPageCommand extends GoToNextPageCommandBase { extendSelection() { return false; } } export class ExtendGoToNextPageCommand extends GoToNextPageCommandBase { extendSelection() { return true; } }