INPUT /  OUTPUT /  LANGUAGE





carat field

Vector field

Sample usage

Applies to...

Behaviour

When one value is provided, positions the cursor before that character. The first character has position 1, and the position after the last character is one more than the length of the text: in {hello world}, position 12. When two values i,j are provided, creates a text selection spanning from character i to character j inclusive. The position i must precede position j in the text otherwise the selection is not valid. The positions mean the same as they do for the .@ operator, so a selection covers exactly the characters that .@ would pick with the same two numbers: <i.carat 1,-1> selects all the text, and <i.carat -3,-1> the last three characters. The value 0 represents the position after the last character in the text. Negative values indicate characters counted from the end instead of from the start, so carat=-1 positions the carat in front of the last character in the text. When read, the carat field always generates positive positions, whichever way they were set: after <i.carat 0> on {hello world}, i.carat generates 12. An editable element keeps its carat position when it loses keyboard focus, so a button can still read it: <button {Insert} onClick=<putLn i.carat>> tells the program where the user was typing. An element that has never had a carat, such as an editable box the user hasn't clicked into yet, has no position, and its carat field generates invalid; <invalid i.carat> tests for this. Assigning null or invalid leaves the carat where it is. A position read earlier can therefore always be assigned back, even if it was invalid.

See also