Skip to content

Commit 6586638

Browse files
authored
Merge pull request #314 from Nexters/develop
[운영 배포] iOS 웹 브라우저 환경에서 한글 IME 입력 버퍼가 비워지지 않아 의도하지 않은 입력이 발생하는 문제 수정
2 parents 7081717 + 2bc864d commit 6586638

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

apps/admin/src/components/QuillEditor/QuillEditor.styles.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ const Container = styled.div<{ error?: boolean; readOnly?: boolean }>`
8585
margin: 0;
8686
padding: 0;
8787
}
88-
89-
li[data-list='bullet'] {
90-
list-style-type: disc;
91-
}
92-
93-
li[data-list='ordered'] {
94-
list-style-type: decimal;
95-
}
96-
88+
9789
a {
9890
color: #46a6ff;
9991
text-decoration-line: underline;

apps/admin/src/components/QuillEditor/index.tsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
2-
import Quill from 'quill';
2+
import Quill, { Range as QuillRange } from 'quill';
33
import { useUploadShowContentImage } from '@boolti/api';
44
import Styled from './QuillEditor.styles';
55
import './blot';
@@ -83,7 +83,7 @@ const QuillEditor: React.FC<EditorProps> = ({
8383
const editorElement = editorElementRef.current;
8484
if (!editorElement) return;
8585

86-
const quill = new Quill(editorElement, {
86+
quillRef.current = new Quill(editorElement, {
8787
modules: {
8888
toolbar: {
8989
container: [
@@ -96,14 +96,39 @@ const QuillEditor: React.FC<EditorProps> = ({
9696
video: videoUploadHandler,
9797
},
9898
},
99+
keyboard: {
100+
bindings: {
101+
enter: {
102+
key: 'Enter',
103+
collapsed: true,
104+
handler: (range: QuillRange) => {
105+
if (!quillRef.current || !document.activeElement) return
106+
107+
const selection = document.getSelection();
108+
selection?.removeAllRanges();
109+
quillRef.current.setSelection(range.index, 0);
110+
111+
/*
112+
* iOS 웹 브라우저 환경에서 발생하는 한글 IME 입력 버퍼 이슈를 해결하기 위한 코드
113+
* Selection.addRange 실행 시 일부러 에러를 발생시켜, 강제로 버퍼를 비우게 한다.
114+
* try catch 문으로 wrap하면 버퍼가 비워지지 않으니 주의할 것.
115+
*/
116+
selection?.addRange({} as Range);
117+
118+
quillRef.current.insertText(range.index, '\n');
119+
quillRef.current.focus()
120+
121+
return false;
122+
}
123+
},
124+
},
125+
},
99126
},
100127
placeholder,
101128
readOnly,
102129
theme: 'snow',
103130
});
104131

105-
quillRef.current = quill;
106-
107132
if (defaultValueRef.current) {
108133
quillRef.current.clipboard.dangerouslyPasteHTML(defaultValueRef.current);
109134
}
@@ -119,20 +144,19 @@ const QuillEditor: React.FC<EditorProps> = ({
119144
onBlurRef.current?.(!text);
120145
});
121146

122-
123147
// 한글 입력 IME 입력 이벤트 감지 및 강제 리렌더링
124148
quillRef.current.root.addEventListener('compositionstart', () => {
125149
setTimeout(() => {
126-
quill.root.classList.remove('ql-blank');
150+
quillRef.current?.root.classList.remove('ql-blank');
127151
}, 0);
128152
});
129153

130154
quillRef.current.root.addEventListener('input', () => {
131155
setTimeout(() => {
132156
if (quillRef.current?.root.innerText.trim() === '') {
133-
quill.root.classList.add('ql-blank');
157+
quillRef.current.root.classList.add('ql-blank');
134158
} else {
135-
quill.root.classList.remove('ql-blank');
159+
quillRef.current?.root.classList.remove('ql-blank');
136160
}
137161
}, 0);
138162
});

0 commit comments

Comments
 (0)