From fb67c0901c388166ee42b530c792ed3fb38ee769 Mon Sep 17 00:00:00 2001 From: Starryi Date: Tue, 23 Nov 2021 17:21:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-63194=20=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8F=AF=E6=9B=B4=E6=96=B0=E6=8F=90=E9=86=92=E3=80=91=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=8D=E7=94=A8-=E9=80=82=E9=85=8D=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=99=A8=E5=AD=97=E6=AE=B5=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E6=B6=88=E5=A4=B1=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 合成文本,如中文等存在输入-删除-替换的机制,参考JTextComponent#replaceInputMethodText() 所以insertString中不能直接return,而应该抛出异常中断后续字符处理,否则在处理中文等合成文本时 会导致原有字符被删除 【改动思路】 同上 --- .../com/fr/design/share/ui/generate/ShareMainPane.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/share/ui/generate/ShareMainPane.java b/designer-realize/src/main/java/com/fr/design/share/ui/generate/ShareMainPane.java index 7bcad336f..5639b5957 100644 --- a/designer-realize/src/main/java/com/fr/design/share/ui/generate/ShareMainPane.java +++ b/designer-realize/src/main/java/com/fr/design/share/ui/generate/ShareMainPane.java @@ -818,14 +818,17 @@ public class ShareMainPane extends JPanel { @Override public void insertString(int offset, String str, AttributeSet attrSet) throws BadLocationException { if (str == null) { - return; + throw new BadLocationException(null, offset); } int count = str.length(); for (int i = 0; i < count; i++) { char c = str.charAt(i); if (allowCharAsString.indexOf(c) < 0) { java.awt.Toolkit.getDefaultToolkit().beep(); - return; + // REPORT-63194 + // 合成文本,如中文等存在输入-删除-替换的机制 JTextComponent#replaceInputMethodText() + // 所以这里不能直接return,而应该抛出异常中断后续字符处理,否则在处理中文等合成文本时会导致原有字符被删除 + throw new BadLocationException(str, offset); } } super.insertString(offset, str, attrSet);