mirror of
https://github.com/coaidev/coai.git
synced 2025-05-22 06:20:14 +09:00
fix: support meta+enter send key in macos platform (#160)
Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com>
This commit is contained in:
parent
b07d421966
commit
0ddd2d2a89
@ -6,7 +6,7 @@ import { useSelector } from "react-redux";
|
|||||||
import { senderSelector } from "@/store/settings.ts";
|
import { senderSelector } from "@/store/settings.ts";
|
||||||
import { blobEvent } from "@/events/blob.ts";
|
import { blobEvent } from "@/events/blob.ts";
|
||||||
import { cn } from "@/components/ui/lib/utils.ts";
|
import { cn } from "@/components/ui/lib/utils.ts";
|
||||||
import { isEnter } from "@/utils/base.ts";
|
import { isEnter, withCtrl, withShift } from "@/utils/base.ts";
|
||||||
|
|
||||||
type ChatInputProps = {
|
type ChatInputProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -47,7 +47,7 @@ function ChatInput({
|
|||||||
// on Enter, clear the input
|
// on Enter, clear the input
|
||||||
// on Ctrl + Enter or Shift + Enter, keep the input
|
// on Ctrl + Enter or Shift + Enter, keep the input
|
||||||
|
|
||||||
if (!e.ctrlKey && !e.shiftKey) {
|
if (!withCtrl(e) && !withShift(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onEnterPressed();
|
onEnterPressed();
|
||||||
} else {
|
} else {
|
||||||
@ -67,9 +67,8 @@ function ChatInput({
|
|||||||
onValueChange(input.value);
|
onValueChange(input.value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// on Enter, keep the input
|
// on Enter, keep the input & on Ctrl + Enter, send the input
|
||||||
// on Ctrl + Enter, clear the input
|
if (withCtrl(e)) {
|
||||||
if (e.ctrlKey) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onEnterPressed();
|
onEnterPressed();
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,19 @@ export function isEnter<T extends HTMLElement>(
|
|||||||
return e.key === "Enter" && e.keyCode != 229;
|
return e.key === "Enter" && e.keyCode != 229;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function withCtrl<T extends HTMLElement>(
|
||||||
|
e: React.KeyboardEvent<T> | KeyboardEvent,
|
||||||
|
): boolean {
|
||||||
|
// if platform is Mac, use Command instead of Ctrl
|
||||||
|
return e.ctrlKey || e.metaKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function withShift<T extends HTMLElement>(
|
||||||
|
e: React.KeyboardEvent<T> | KeyboardEvent,
|
||||||
|
): boolean {
|
||||||
|
return e.shiftKey;
|
||||||
|
}
|
||||||
|
|
||||||
export function resetJsArray<T>(arr: T[], target: T[]): T[] {
|
export function resetJsArray<T>(arr: T[], target: T[]): T[] {
|
||||||
/**
|
/**
|
||||||
* this function is used to reset an array to another array without changing the *pointer
|
* this function is used to reset an array to another array without changing the *pointer
|
||||||
|
Loading…
Reference in New Issue
Block a user