MCPcopy Create free account
hub / github.com/adobe/react-spectrum / selectNextToken

Function selectNextToken

packages/@react-spectrum/ai/src/PromptField.tsx:820–839  ·  view source on GitHub ↗
(
  prompt: PromptFieldValue,
  dir: number,
  placeholder = false
)

Source from the content-addressed store, hash-verified

818}
819
820function selectNextToken(
821 prompt: PromptFieldValue,
822 dir: number,
823 placeholder = false
824): PromptFieldValue | null {
825 let index = prompt.caretPosition.index;
826 for (let i = index + dir; i >= 0 && i < prompt.segments.length; i += dir) {
827 let segment = prompt.segments[i];
828 if (segment.type === 'token' && (!placeholder || segment.value?.type === 'placeholder')) {
829 return prompt.withSelectedRange(
830 new TokenFieldValue.SelectedRange(
831 {index: i, offset: 0},
832 {index: i, offset: segment.text.length}
833 )
834 );
835 }
836 }
837
838 return null;
839}
840
841export interface PromptTokenFieldPopoverProps extends Omit<PopoverProps, 'shouldSkipAnimation'> {
842 filterAnchor?: Position | null;

Callers 2

tabFunction · 0.85
useInsertPromptSegmentFunction · 0.85

Calls 1

withSelectedRangeMethod · 0.80

Tested by

no test coverage detected