Skip to content
This repository was archived by the owner on Feb 28, 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
12 changes: 10 additions & 2 deletions src/components/ChatForm/useInputValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export function useInputValue(
(event: MessageEvent) => {
if (addInputValue.match(event.data) || setInputValue.match(event.data)) {
const { payload } = event.data;
debugRefact(`[DEBUG]: receiving event setInputValue/addInputValue`);
debugRefact(
`[DEBUG]: receiving event setInputValue/addInputValue with payload:`,
payload,
);
setUpIfNotReady();

if (payload.messages) {
Expand All @@ -49,14 +52,19 @@ export function useInputValue(

if (addInputValue.match(event.data)) {
const { payload } = event.data;
debugRefact(`[DEBUG]: addInputValue triggered with:`, payload);
const { send_immediately, value } = payload;
setValue((prev) => prev + value);
setValue((prev) => {
debugRefact(`[DEBUG]: Previous value: "${prev}", Adding: "${value}"`);
return prev + value;
});
setIsSendImmediately(send_immediately);
return;
}

if (setInputValue.match(event.data)) {
const { payload } = event.data;
debugRefact(`[DEBUG]: setInputValue triggered with:`, payload);
const { send_immediately, value } = payload;
uncheckCheckboxes();
setValue(value ?? "");
Expand Down
16 changes: 12 additions & 4 deletions src/components/ComboBox/ComboBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ describe("ComboBox", () => {
await user.keyboard("{z}");
expect(textarea.textContent).toEqual("@file ");

await pause(100); // required, because of cancelling on frequent paste

await user.keyboard("{z}{/Meta}{/Shift}");
expect(textarea.textContent).toEqual("@file /foo ");
});
Expand All @@ -387,23 +389,29 @@ describe("ComboBox", () => {

await user.type(textarea, "@");
await user.keyboard("{Enter}");
await pause(50);
await pause(150);
await user.keyboard("{Enter}");

expect(textarea.textContent).toEqual("@file /foo ");

await user.keyboard("{Control>}{z}");
expect(textarea.textContent).toEqual("@file ");

await user.keyboard("{z}");
expect(textarea.textContent).toEqual("@");

await user.keyboard("{z}{/Control}");
expect(textarea.textContent).toEqual("");

await user.keyboard("{Shift>}{Control>}{z}");
await user.keyboard("{Shift>}{Control>}{Z}");
expect(textarea.textContent).toEqual("@");
await user.keyboard("{z}");

await user.keyboard("{Z}");
expect(textarea.textContent).toEqual("@file ");

await user.keyboard("{z}{/Control}{/Shift}");
await pause(100); // required, because of cancelling on frequent paste

await user.keyboard("{z}{/Shift}{/Control}");
expect(textarea.textContent).toEqual("@file /foo ");
});

Expand Down
28 changes: 25 additions & 3 deletions src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
}) => {
const ref = React.useRef<HTMLTextAreaElement>(null);
const [moveCursorTo, setMoveCursorTo] = React.useState<number | null>(null);
const [lastPasteTimestamp, setLastPasteTimestamp] = React.useState(0);
const shiftEnterToSubmit = useAppSelector(selectSubmitOption);
const { escapeKeyPressed } = useEventsBusForIDE();

Expand Down Expand Up @@ -198,9 +199,30 @@ export const ComboBox: React.FC<ComboBoxProps> = ({

const handleChange = useCallback(
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange(event.target.value);
const newValue = event.target.value;
const nativeEvent = event.nativeEvent as InputEvent;
const currentEventTimestamp = nativeEvent.timeStamp;

const inputType = nativeEvent.inputType;
const isPasteEvent = [
"insertFromPaste",
"insertFromDrop",
"insertFromYank",
"insertReplacementText",
].includes(inputType);

const timeSinceLastChange = currentEventTimestamp - lastPasteTimestamp;

if (isPasteEvent && timeSinceLastChange < 100) return;

if (isPasteEvent) {
setLastPasteTimestamp(currentEventTimestamp);
closeCombobox();
requestCommandsCompletion.cancel();
}
onChange(newValue);
},
[onChange],
[onChange, closeCombobox, requestCommandsCompletion, lastPasteTimestamp],
);

const onItemClick = useCallback(
Expand Down Expand Up @@ -240,7 +262,7 @@ export const ComboBox: React.FC<ComboBoxProps> = ({
showOnChange={false}
showOnKeyDown={false}
showOnMouseDown={false}
setValueOnChange={true}
setValueOnChange={false}
render={render({
ref,
placeholder,
Expand Down
6 changes: 4 additions & 2 deletions src/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
const handleKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
const isMod = event.metaKey || event.ctrlKey;
if (isMod && event.key === "z" && !event.shiftKey) {
const eventKey = event.key.toLowerCase();

if (isMod && eventKey === "z" && !event.shiftKey) {
event.preventDefault();
undoRedo.undo();
setCallChange(true);
}

if (isMod && event.key === "z" && event.shiftKey) {
if (isMod && eventKey === "z" && event.shiftKey) {
event.preventDefault();
undoRedo.redo();
setCallChange(true);
Expand Down