SetSelectionRange

Forms, interaction, Unicode

Description

Sets the anchor and caret of the active form-field edit selection in the requested index unit

The two positions are clamped independently, so an anchor greater than the caret creates a reversed selection while the normalized SelectionStart and SelectionLength properties remain ordered

Code-point and grapheme-cluster units always resolve to valid Unicode boundaries and cannot divide a surrogate pair, combining sequence or joined emoji cluster

Declaration

function SetSelectionRange(AnchorIndex, CaretIndex: Integer;
  IndexUnit: TPDFlibFormSelectionUnit): Integer;

Parameters

AnchorIndexFixed edge of the directed selection in IndexUnit, clamped to the editable value
CaretIndexMoving edge of the directed selection in IndexUnit, clamped to the editable value
IndexUnitfsuUTF16CodeUnit, fsuUnicodeCodePoint or fsuGraphemeCluster

Return value

Returns 1 when an edit is active and the selection is stored, otherwise 0

Performance

Code-point and grapheme boundary tables are built lazily for the current edit value, reused by later selection operations and invalidated by SetEditValue

Example

if Session.BeginEdit(FieldIndex) = 1 then
begin
  Session.SetEditValue('A' + WideChar($D83D) + WideChar($DE00) + 'B');
  Session.SetSelectionRange(1, 2, fsuUnicodeCodePoint);
end;

See also

GetSelectionRange, TPDFlibFormSession