Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
fix: newline shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
clement2026 committed Dec 19, 2023
1 parent 0a2cf37 commit e09d710
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/home/chat-window/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const TextArea: React.FC<Props> = ({chatProxy}) => {


const handleKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = useCallback((event) => {
event.stopPropagation()
// never interrupt composing
if (isComposing) {
setLinuxTerminalHistoryIndex(-1)
Expand Down Expand Up @@ -105,8 +104,18 @@ const TextArea: React.FC<Props> = ({chatProxy}) => {
} else {
const sc = appState.pref.shortcuts
if (matchKeyComobo(sc.newLine, event)) {
chatProxy.inputText += "\n"
event.preventDefault()
if (event.key === 'Enter' && !event.ctrlKey && !event.metaKey && !event.altKey) {
// try our best to use native 'new-line', in order to preserve edit stack(ctrl/cmd + z)
} else {
event.preventDefault()
const target = event.currentTarget
const caretPosition = target.selectionStart;
target.value =
target.value.slice(0, caretPosition) +
"\n" +
target.value.slice(caretPosition);
setTimeout(() => target.selectionStart = target.selectionEnd = caretPosition + 1)
}
} else if (matchKeyComobo(sc.send, event)) {
sendAndClearText()
event.preventDefault()
Expand Down

0 comments on commit e09d710

Please sign in to comment.