Skip to content

Commit bea7549

Browse files
bebuslclaude
andcommitted
feat: [FN-351] 한글 IME 조합 완성 시에만 Yjs update emit 처리
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c4871fc commit bea7549

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

src/features/cardset/components/cardset-editor.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ export function CardsetEditor({ cardsetId }: CardsetEditorProps) {
195195

196196
const handleQuestionChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
197197
const newValue = e.target.value;
198+
setQuestionValue(newValue);
199+
if (e.nativeEvent.isComposing) return;
198200
if (hasAccess && questionTextRef.current) {
199201
const oldValue = questionValue;
200202
isUpdatingRef.current = true;
201203
applyDelta(questionTextRef.current, getDelta(oldValue, newValue));
202-
setQuestionValue(newValue);
203204
isUpdatingRef.current = false;
204205
} else {
205-
setQuestionValue(newValue);
206206
setLocalCards((prev) =>
207207
prev.map((card, idx) =>
208208
idx === currentCardIndex ? { ...card, question: newValue } : card,
@@ -211,16 +211,26 @@ export function CardsetEditor({ cardsetId }: CardsetEditorProps) {
211211
}
212212
};
213213

214+
const handleQuestionCompositionEnd = (e: React.CompositionEvent<HTMLTextAreaElement>) => {
215+
const newValue = e.currentTarget.value;
216+
if (hasAccess && questionTextRef.current) {
217+
const oldValue = questionTextRef.current.toString();
218+
isUpdatingRef.current = true;
219+
applyDelta(questionTextRef.current, getDelta(oldValue, newValue));
220+
isUpdatingRef.current = false;
221+
}
222+
};
223+
214224
const handleAnswerChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
215225
const newValue = e.target.value;
226+
setAnswerValue(newValue);
227+
if (e.nativeEvent.isComposing) return;
216228
if (hasAccess && answerTextRef.current) {
217229
const oldValue = answerValue;
218230
isUpdatingRef.current = true;
219231
applyDelta(answerTextRef.current, getDelta(oldValue, newValue));
220-
setAnswerValue(newValue);
221232
isUpdatingRef.current = false;
222233
} else {
223-
setAnswerValue(newValue);
224234
setLocalCards((prev) =>
225235
prev.map((card, idx) =>
226236
idx === currentCardIndex ? { ...card, answer: newValue } : card,
@@ -229,6 +239,16 @@ export function CardsetEditor({ cardsetId }: CardsetEditorProps) {
229239
}
230240
};
231241

242+
const handleAnswerCompositionEnd = (e: React.CompositionEvent<HTMLTextAreaElement>) => {
243+
const newValue = e.currentTarget.value;
244+
if (hasAccess && answerTextRef.current) {
245+
const oldValue = answerTextRef.current.toString();
246+
isUpdatingRef.current = true;
247+
applyDelta(answerTextRef.current, getDelta(oldValue, newValue));
248+
isUpdatingRef.current = false;
249+
}
250+
};
251+
232252
const handleAddCard = () => {
233253
if (hasAccess) {
234254
addCard({ question: "", answer: "" });
@@ -571,6 +591,7 @@ export function CardsetEditor({ cardsetId }: CardsetEditorProps) {
571591
label="질문"
572592
value={questionValue}
573593
onChange={handleQuestionChange}
594+
onCompositionEnd={handleQuestionCompositionEnd}
574595
onFocus={() => {
575596
setFocusedField("question");
576597
if (hasAccess) setAwareness("question", currentCardIndex);
@@ -588,6 +609,7 @@ export function CardsetEditor({ cardsetId }: CardsetEditorProps) {
588609
label="답변"
589610
value={answerValue}
590611
onChange={handleAnswerChange}
612+
onCompositionEnd={handleAnswerCompositionEnd}
591613
onFocus={() => {
592614
setFocusedField("answer");
593615
if (hasAccess) setAwareness("answer", currentCardIndex);
@@ -614,6 +636,7 @@ type EditorFieldProps = {
614636
label: string;
615637
value: string;
616638
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
639+
onCompositionEnd: (e: React.CompositionEvent<HTMLTextAreaElement>) => void;
617640
onFocus: () => void;
618641
onBlur: () => void;
619642
isFocused: boolean;
@@ -627,6 +650,7 @@ function EditorField({
627650
label,
628651
value,
629652
onChange,
653+
onCompositionEnd,
630654
onFocus,
631655
onBlur,
632656
isFocused,
@@ -672,6 +696,7 @@ function EditorField({
672696
id={id}
673697
value={value}
674698
onChange={onChange}
699+
onCompositionEnd={onCompositionEnd}
675700
onFocus={onFocus}
676701
onBlur={onBlur}
677702
className="w-full min-h-40 text-base leading-relaxed resize-none border-0 bg-transparent focus:ring-0 focus:outline-none px-5 pb-5 pt-2 text-gray-800 placeholder:text-gray-400"

0 commit comments

Comments
 (0)