< prev index next >

src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java

Print this page

        

@@ -32,10 +32,12 @@
 import java.text.*;
 import javax.swing.Action;
 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
  * to be a reasonably functioning editor for some <em>type</em>
  * of text document.  This implementation provides a default

@@ -1068,10 +1070,25 @@
 
                             if (c0 >= '\uD800' && c0 <= '\uDBFF' &&
                                 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);
                         beep = false;
                     }

@@ -1116,14 +1133,35 @@
 
                         if (dot < doc.getLength() - 1) {
                             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;
+                                    }
+                                }
                             }
                         }
 
                         doc.remove(dot, delChars);
                         beep = false;
< prev index next >