Skip to content

Commit c0ecff9

Browse files
committed
fix: pinyin keyboard
1 parent d4fca9d commit c0ecff9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib/components/chat/MessageInput.svelte

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
let loaded = false;
8686
let recording = false;
8787
88+
let isComposing = false;
89+
8890
let chatInputContainerElement;
8991
let chatInputElement;
9092
@@ -707,6 +709,8 @@
707709
console.log(res);
708710
return res;
709711
}}
712+
oncompositionstart={() => (isComposing = true)}
713+
oncompositionend={() => (isComposing = false)}
710714
on:keydown={async (e) => {
711715
e = e.detail.event;
712716

@@ -806,6 +810,10 @@
806810
navigator.msMaxTouchPoints > 0
807811
)
808812
) {
813+
if (isComposing) {
814+
return;
815+
}
816+
809817
// Uses keyCode '13' for Enter key for chinese/japanese keyboards.
810818
//
811819
// Depending on the user's settings, it will send the message
@@ -882,6 +890,8 @@
882890
class="scrollbar-hidden bg-transparent dark:text-gray-100 outline-hidden w-full pt-3 px-1 resize-none"
883891
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
884892
bind:value={prompt}
893+
on:compositionstart={() => (isComposing = true)}
894+
on:compositionend={() => (isComposing = false)}
885895
on:keydown={async (e) => {
886896
const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
887897

@@ -983,6 +993,10 @@
983993
navigator.msMaxTouchPoints > 0
984994
)
985995
) {
996+
if (isComposing) {
997+
return;
998+
}
999+
9861000
console.log('keypress', e);
9871001
// Prevent Enter key from creating a new line
9881002
const isCtrlPressed = e.ctrlKey || e.metaKey;

src/lib/components/common/RichTextInput.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
2828
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
2929
30+
export let oncompositionstart = (e) => {};
31+
export let oncompositionend = (e) => {};
32+
3033
// create a lowlight instance with all languages loaded
3134
const lowlight = createLowlight(all);
3235
@@ -226,6 +229,14 @@
226229
editorProps: {
227230
attributes: { id },
228231
handleDOMEvents: {
232+
compositionstart: (view, event) => {
233+
oncompositionstart(event);
234+
return false;
235+
},
236+
compositionend: (view, event) => {
237+
oncompositionend(event);
238+
return false;
239+
},
229240
focus: (view, event) => {
230241
eventDispatch('focus', { event });
231242
return false;

0 commit comments

Comments
 (0)