engine/model/utils/modifyselection
module
Functions
modifySelection( model, selection, options = { [options.direction], [options.treatEmojiAsSingleUnit], [options.unit] } ) → voidinternalmodule:engine/model/utils/modifyselection~modifySelectionModifies the selection. Currently, the supported modifications are:
- Extending. The selection focus is moved in the specified
options.directionwith a step specified inoptions.unit. Possible values forunitare: 'character'(default) - moves selection by one user-perceived character. In most cases this means moving by one character inStringsense. However, unicode also defines "combing marks". These are special symbols, that combines with a symbol before it ("base character") to create one user-perceived character. For example,q̣̇is a normal letterqwith two "combining marks": upper dot (Ux0307) and lower dot (Ux0323). For most actions, i.e. extending selection by one position, it is correct to include both "base character" and all of it's "combining marks". That is why'character'value is most natural and common method of modifying selection.'codePoint'- moves selection by one unicode code point. In contrary to,'character'unit, this will insert selection between "base character" and "combining mark", because "combining marks" have their own unicode code points. However, for technical reasons, unicode code points with values aboveUxFFFFare represented in nativeStringby two characters, called "surrogate pairs". Halves of "surrogate pairs" have a meaning only when placed next to each other. For example𨭎is represented inStringby\uD862\uDF4E. Both\uD862and\uDF4Edo not have any meaning outside the pair (are rendered as ? when alone). Position between them would be incorrect. In this case, selection extension will include whole "surrogate pair".'word'- moves selection by a whole word.
Note: if you extend a forward selection in a backward direction you will in fact shrink it.
Note: Use
modifySelectioninstead of this function. This function is only exposed to be reusable in algorithms which change themodifySelectionmethod's behavior.Parameters
model : ModelThe model in context of which the selection modification should be performed.
selection : ModelSelection | ModelDocumentSelectionThe selection to modify.
options : object- Properties
[ options.direction ] : 'forward' | 'backward'The direction in which the selection should be modified. Default 'forward'.
[ options.treatEmojiAsSingleUnit ] : booleanWhether multi-characer emoji sequences should be handled as single unit.
[ options.unit ] : 'character' | 'codePoint' | 'word'The unit by which selection should be modified. Default 'character'.
Defaults to
{}
Returns
void
- Extending. The selection focus is moved in the specified