SetSelectionRange

表单、交互、Unicode

描述

以请求的索引单位设置活动表单字段编辑选择的锚点与插入符

两个位置独立钳制,因此锚点大于插入符会形成反向选择,而规范化后的 SelectionStart 与 SelectionLength 属性仍保持有序

码点单位和字素簇单位总是解析到有效的 Unicode 边界,不会拆分代理对、组合序列或连写的 emoji 簇

声明

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

参数

AnchorIndex有向选定在 IndexUnit 下的固定边,限制到可编辑值
CaretIndex有向选定在 IndexUnit 下的移动边,限制到可编辑值
IndexUnitfsuUTF16CodeUnit、fsuUnicodeCodePoint 或 fsuGraphemeCluster

返回值

有活动编辑且选定已存储时返回 1,否则返回 0

性能

代码点和字素边界表针对当前编辑值惰性构建,供后续选定操作复用,并在 SetEditValue 时失效

示例

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

另请参阅

GetSelectionRange, TPDFlibFormSession