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

Function selectNextToken

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

Source from the content-addressed store, hash-verified

764}
765
766function selectNextToken(
767 prompt: PromptFieldValue,
768 dir: number,
769 placeholder = false
770): PromptFieldValue | null {
771 let index = prompt.caretPosition.index;
772 for (let i = index + dir; i >= 0 && i < prompt.segments.length; i += dir) {
773 let segment = prompt.segments[i];
774 if (segment.type === 'token' && (!placeholder || segment.value?.type === 'placeholder')) {
775 return prompt.withSelectedRange(
776 new TokenFieldValue.SelectedRange(
777 {index: i, offset: 0},
778 {index: i, offset: segment.text.length}
779 )
780 );
781 }
782 }
783
784 return null;
785}
786
787export interface PromptTokenFieldPopoverProps extends Omit<PopoverProps, 'shouldSkipAnimation'> {
788 filterAnchor?: Position | null;

Callers 2

tabFunction · 0.85
useInsertPromptSegmentFunction · 0.85

Calls 1

withSelectedRangeMethod · 0.80

Tested by

no test coverage detected