mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Handle composition input in PDF text editor (#5192)
## Summary - track IME composition state in the PDF text editor to avoid interrupting phonetic input methods - update text syncing to occur after composition completes and skip redundant updates mid-composition ## Testing - npm run lint -- --max-warnings 0 ------ [Codex Task](https://chatgpt.com/codex/tasks/task_b_693744be74148328bd3bda9150de6e56)
This commit is contained in:
+1
-1
@@ -57,7 +57,7 @@ repositories {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = 'stirling.software'
|
group = 'stirling.software'
|
||||||
version = '2.1.1'
|
version = '2.1.2'
|
||||||
|
|
||||||
configurations.configureEach {
|
configurations.configureEach {
|
||||||
exclude group: 'commons-logging', module: 'commons-logging'
|
exclude group: 'commons-logging', module: 'commons-logging'
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ const PdfTextEditorView = ({ data }: PdfTextEditorViewProps) => {
|
|||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const editorRefs = useRef<Map<string, HTMLDivElement>>(new Map());
|
const editorRefs = useRef<Map<string, HTMLDivElement>>(new Map());
|
||||||
const caretOffsetsRef = useRef<Map<string, number>>(new Map());
|
const caretOffsetsRef = useRef<Map<string, number>>(new Map());
|
||||||
|
const composingGroupsRef = useRef<Set<string>>(new Set());
|
||||||
const lastSelectedGroupIdRef = useRef<string | null>(null);
|
const lastSelectedGroupIdRef = useRef<string | null>(null);
|
||||||
const widthOverridesRef = useRef<Map<string, number>>(widthOverrides);
|
const widthOverridesRef = useRef<Map<string, number>>(widthOverrides);
|
||||||
const resizingRef = useRef<{
|
const resizingRef = useRef<{
|
||||||
@@ -614,6 +615,18 @@ const PdfTextEditorView = ({ data }: PdfTextEditorViewProps) => {
|
|||||||
[editingGroupId, onGroupEdit],
|
[editingGroupId, onGroupEdit],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleCompositionStart = useCallback((groupId: string) => {
|
||||||
|
composingGroupsRef.current.add(groupId);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCompositionEnd = useCallback(
|
||||||
|
(element: HTMLElement, pageIndex: number, groupId: string) => {
|
||||||
|
composingGroupsRef.current.delete(groupId);
|
||||||
|
syncEditorValue(element, pageIndex, groupId);
|
||||||
|
},
|
||||||
|
[syncEditorValue],
|
||||||
|
);
|
||||||
|
|
||||||
const handleMergeSelection = useCallback(() => {
|
const handleMergeSelection = useCallback(() => {
|
||||||
if (!canMergeSelection) {
|
if (!canMergeSelection) {
|
||||||
return;
|
return;
|
||||||
@@ -2279,6 +2292,10 @@ const selectionToolbarPosition = useMemo(() => {
|
|||||||
contentEditable
|
contentEditable
|
||||||
suppressContentEditableWarning
|
suppressContentEditableWarning
|
||||||
data-editor-group={group.id}
|
data-editor-group={group.id}
|
||||||
|
onCompositionStart={() => handleCompositionStart(group.id)}
|
||||||
|
onCompositionEnd={(event) =>
|
||||||
|
handleCompositionEnd(event.currentTarget, group.pageIndex, group.id)
|
||||||
|
}
|
||||||
onFocus={(event) => {
|
onFocus={(event) => {
|
||||||
const primaryFont = fontFamily.split(',')[0]?.replace(/['"]/g, '').trim();
|
const primaryFont = fontFamily.split(',')[0]?.replace(/['"]/g, '').trim();
|
||||||
if (primaryFont && typeof document !== 'undefined') {
|
if (primaryFont && typeof document !== 'undefined') {
|
||||||
@@ -2300,6 +2317,7 @@ const selectionToolbarPosition = useMemo(() => {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}}
|
}}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
|
composingGroupsRef.current.delete(group.id);
|
||||||
syncEditorValue(event.currentTarget, group.pageIndex, group.id, {
|
syncEditorValue(event.currentTarget, group.pageIndex, group.id, {
|
||||||
skipCaretRestore: true,
|
skipCaretRestore: true,
|
||||||
});
|
});
|
||||||
@@ -2309,6 +2327,9 @@ const selectionToolbarPosition = useMemo(() => {
|
|||||||
setEditingGroupId(null);
|
setEditingGroupId(null);
|
||||||
}}
|
}}
|
||||||
onInput={(event) => {
|
onInput={(event) => {
|
||||||
|
if (composingGroupsRef.current.has(group.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
syncEditorValue(event.currentTarget, group.pageIndex, group.id);
|
syncEditorValue(event.currentTarget, group.pageIndex, group.id);
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user