Skip to content

Commit 62c67a1

Browse files
committed
fix space mobile
1 parent 68be78a commit 62c67a1

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/components/IMEField.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,28 +219,36 @@ export function IMEField() {
219219
setLastConversion(null);
220220
return;
221221
}
222+
}
223+
224+
function handleInput(
225+
e: InputEvent & {
226+
currentTarget: HTMLTextAreaElement;
227+
}
228+
) {
229+
const val = e.currentTarget.value;
230+
const pos = e.currentTarget.selectionStart;
222231

223-
if (e.key === " " && isComposing()) {
232+
if (isComposing() && e.inputType === "insertText" && (e.data === " " || e.data === null)) {
224233
const start = confirmedIndex();
225-
const pos = e.currentTarget.selectionStart;
226-
const reading = input().slice(start, pos);
234+
const reading = val.slice(start, pos - 1);
227235

228236
if (wanakana.isHiragana(reading) && reading.length) {
229-
e.preventDefault();
237+
const newVal = val.slice(0, pos - 1) + val.slice(pos);
238+
setInput(newVal);
239+
if (ta) {
240+
ta.value = newVal;
241+
ta.setSelectionRange(newVal.length, newVal.length);
242+
}
243+
230244
setCompositionStart(start);
231245
setLookupReading(reading);
232246
setSelectedIndex(0);
233247
setIsMenuOpen(true);
248+
return;
234249
}
235250
}
236-
}
237251

238-
function handleInput(
239-
e: InputEvent & {
240-
currentTarget: HTMLTextAreaElement;
241-
}
242-
) {
243-
const val = e.currentTarget.value;
244252
setInput(val);
245253
setIsComposing(val.length > confirmedIndex());
246254
setLastConversion(null);
@@ -304,15 +312,16 @@ export function IMEField() {
304312
onCloseAutoFocus={(e) => {
305313
e.preventDefault();
306314
ta?.focus();
307-
}}>
315+
}}
316+
class="w-[var(--kb-popper-content-width)]">
308317
<Suspense fallback={<Spinner />}>
309318
<Show
310319
when={suggestions()?.length > 0}
311320
fallback={
312321
<div class="text-muted-foreground px-2 py-1.5 text-sm">No results found.</div>
313322
}>
314323
<>
315-
<div ref={listRef} class="max-h-[10rem] overflow-y-auto">
324+
<div ref={listRef} class="max-h-[13rem] overflow-y-auto">
316325
<For each={suggestions()}>
317326
{(s, idx) => (
318327
<DropdownMenuItem

0 commit comments

Comments
 (0)