--- old/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java 2018-05-31 15:12:49.000000000 -0700 +++ new/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java 2018-05-31 15:12:48.000000000 -0700 @@ -34,6 +34,8 @@ import javax.swing.KeyStroke; import javax.swing.SwingConstants; import javax.swing.UIManager; +import static sun.font.CharToGlyphMapper.isVariationSelector; +import static sun.font.CharToGlyphMapper.isBaseChar; /** * This is the set of things needed by a text component @@ -1070,6 +1072,21 @@ c1 >= '\uDC00' && c1 <= '\uDFFF') { delChars = 2; } + + // For Variation Selector + if ((dot > 2 && isVariationSelector(c0, c1)) || + (isVariationSelector(c1))) { + String targetChars = doc.getText(0, dot); + int pre = targetChars.codePointBefore( + dot - delChars); + if (isBaseChar(pre)) { + if (pre >= 0x10000) { + delChars += 2; + } else { + delChars += 1; + } + } + } } doc.remove(dot - delChars, delChars); @@ -1118,10 +1135,31 @@ String dotChars = doc.getText(dot, 2); char c0 = dotChars.charAt(0); char c1 = dotChars.charAt(1); + int baseChar = (int)c0; if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') { delChars = 2; + baseChar = (c0 - 0xD800) * 0x400 + c1 - 0xDC00 + + 0x10000; + } + + // For Variation Selector + if (isBaseChar(baseChar) && + dot < doc.getLength() - delChars) { + String nextChar = doc.getText(dot+delChars, 1); + char c2 = nextChar.charAt(0); + if (isVariationSelector(c2)) { + delChars += 1; + } else if (dot < doc.getLength() + - delChars - 1) { + nextChar = doc.getText( + dot + delChars + 1, 1); + char c3 = nextChar.charAt(0); + if (isVariationSelector(c2,c3)) { + delChars += 2; + } + } } }