Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const SchemaField: React.FC<FieldProps> = (props) => {
typeof uiOptions?.serializer?.set === 'function' ? uiOptions.serializer.set(newValue) : newValue;

onChange(serializedValue);
setFieldFocused(true);
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@ export const IntellisenseTextField: React.FC<FieldProps<string>> = (props) => {
onBlur={props.onBlur}
onChange={onChange}
>
{({ textFieldValue, focused, onValueChanged, onKeyDownTextField, onKeyUpTextField, onClickTextField }) => (
{({
textFieldValue,
focused,
cursorPosition,
onValueChanged,
onKeyDownTextField,
onKeyUpTextField,
onClickTextField,
}) => (
<StringField
{...props}
cursorPosition={cursorPosition}
focused={focused}
id={id}
value={textFieldValue}
Expand Down Expand Up @@ -84,9 +93,18 @@ export const IntellisenseExpressionField: React.FC<FieldProps<string>> = (props)
onBlur={props.onBlur}
onChange={onChange}
>
{({ textFieldValue, focused, onValueChanged, onKeyDownTextField, onKeyUpTextField, onClickTextField }) => (
{({
textFieldValue,
focused,
cursorPosition,
onValueChanged,
onKeyDownTextField,
onKeyUpTextField,
onClickTextField,
}) => (
<StringField
{...props}
cursorPosition={cursorPosition}
focused={focused}
id={id}
value={textFieldValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const StringField: React.FC<FieldProps<string>> = function StringField(pr
uiOptions,
required,
focused,
cursorPosition,
} = props;

const textFieldRef = React.createRef<ITextField>();
Expand All @@ -49,7 +50,13 @@ export const StringField: React.FC<FieldProps<string>> = function StringField(pr
if (focused && textFieldRef.current) {
textFieldRef.current.focus();
}
}, [focused, textFieldRef.current]);
}, [focused, textFieldRef.current, value]);

useEffect(() => {
if (cursorPosition !== undefined && cursorPosition > -1 && textFieldRef.current) {
textFieldRef.current.setSelectionRange(cursorPosition, cursorPosition);
}
}, [cursorPosition]);

const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {
if (typeof onFocus === 'function') {
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/extension-client/src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface FieldProps<T = any> {
value?: T;
focused?: boolean;
style?: React.CSSProperties;
cursorPosition?: number;

onChange: ChangeHandler<T>;
onFocus?: (id: string, value?: T) => void;
Expand Down
12 changes: 11 additions & 1 deletion Composer/packages/intellisense/src/components/Intellisense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Intellisense = React.memo(
children: (renderProps: {
textFieldValue: any;
focused?: boolean;
cursorPosition?: number;
onValueChanged: (newValue: any) => void;
onKeyDownTextField: (event: React.KeyboardEvent<HTMLInputElement>) => void;
onKeyUpTextField: (event: React.KeyboardEvent<HTMLInputElement>) => void;
Expand Down Expand Up @@ -141,6 +142,7 @@ export const Intellisense = React.memo(
selectedSuggestion +
textFieldValue.substr(range.end.character);
onValueChanged(newValue);
setCursorPosition(range.start.character + selectedSuggestion.length);
} else {
onValueChanged(selectedSuggestion);
}
Expand Down Expand Up @@ -197,7 +199,15 @@ export const Intellisense = React.memo(

return (
<div onKeyUp={onKeyUpMainComponent} ref={mainContainerRef} style={{ position: 'relative' }}>
{children({ textFieldValue, focused, onValueChanged, onKeyDownTextField, onKeyUpTextField, onClickTextField })}
{children({
textFieldValue,
focused,
cursorPosition,
onValueChanged,
onKeyDownTextField,
onKeyUpTextField,
onClickTextField,
})}

{completionListOverride || showCompletionList ? (
<CompletionList
Expand Down