ReplaceSelection

Forms, interaction, Unicode

Description

Replaces the normalized selection in the active text field or editable combo box and collapses the caret after the accepted replacement

The session first dispatches the field's /K action through OnAction, then calls OnTextEdit with the selected text and a mutable replacement

A veto leaves the edit value, selection, modified state and document field unchanged

Text-field /MaxLen limits preserve the existing prefix and suffix, truncate only the inserted text and never divide an extended grapheme cluster

Declaration

function ReplaceSelection(
  const ReplacementText: WideString): Integer;

Parameters

ReplacementTextText proposed for the current normalized selection before host modification and length enforcement

Return value

Returns 1 when the replacement is accepted, including a no-op replacement, otherwise 0

Example

if Session.SetSelectionRange(1, 3, fsuGraphemeCluster) = 1 then
  Session.ReplaceSelection('approved');

See also

CutSelection, PasteText, SetSelectionRange, TPDFlibFormSession