UNPKG

devexpress-richedit

Version:

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

31 lines (30 loc) 1.7 kB
import { LayoutWordBounds } from '../../word-bounds-engine/layout-word-bounds'; import { ExtendGoToNextCharacterCommand } from './go-to-next-character-command'; import { SelectionCommandBase } from './selection-command-base'; export class GoToNextWordCommandBase extends SelectionCommandBase { getStartPosition() { var selection = this.selection; return selection.forwardDirection ? selection.lastSelectedInterval.end : selection.lastSelectedInterval.start; } } export class GoToNextWordCommand extends GoToNextWordCommandBase { executeCore(_state, _options) { const selection = this.selection; const subDocument = this.selection.activeSubDocument; this.control.ensureDocumentIsFullyFormatted(); let position = LayoutWordBounds.getLayoutWordEndBound(this.control.layout, subDocument, selection, this.getStartPosition(), true); if (position == subDocument.getDocumentEndPosition()) position--; selection.deprecatedSetSelection(position, position, false, selection.keepX, true); return true; } } export class ExtendGoToNextWordCommand extends GoToNextWordCommandBase { executeCore(_state, _options) { this.control.ensureDocumentIsFullyFormatted(); const position = LayoutWordBounds.getLayoutWordEndBound(this.control.layout, this.selection.activeSubDocument, this.selection, this.getStartPosition(), true); if (!this.selection.changeState((newState) => newState.extendLastInterval(position).resetKeepX().setEndOfLine(false))) ExtendGoToNextCharacterCommand.jumpThroughFieldToRight(this.selection); return true; } }