< prev index next >

modules/graphics/src/main/java/com/sun/glass/ui/mac/MacView.java

Print this page

        

@@ -28,10 +28,11 @@
 import com.sun.glass.ui.View;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.IntBuffer;
 import java.util.Map;
+import java.util.TreeSet;
 
 /**
  * MacOSX platform implementation class for View.
  */
 final class MacView extends View {

@@ -116,21 +117,45 @@
     public void hostRemoteLayerId(int nativeLayerId) {
         // used when run inside plugin
         _hostRemoteLayerId(getNativeLayer(), nativeLayerId);
     }
     
-    protected void notifyInputMethodMac(String str, int attrib, int length, int cursor) {
+    protected void notifyInputMethodMac(String str, int attrib, int length,
+                                            int cursor, int selStart, int selLength) {
         byte atts[] = new byte[1];
         atts[0] = (byte) attrib;
         int attBounds[] = new int[2];
         attBounds[0] = 0;
         attBounds[1] = length;
         if(attrib == 4) {
             // attrib == 4 means we are going to commit changes, so commitLength should be non-zero
             notifyInputMethod(str, null, attBounds, atts, length, cursor, 0);
         } else {
             // all other cases = just an update, update preview text but do not commit it
+            if (selLength > 0
+                    && str != null && str.length() > 0
+                    && selStart >= 0
+                    && selLength + selStart <= str.length()) {
+
+                TreeSet<Integer> b = new TreeSet<>();
+                b.add(0);
+                b.add(selStart);
+                b.add(selStart + selLength);
+                b.add(str.length());
+
+                int[] boundary = b.stream().mapToInt(Integer::intValue).toArray();
+                byte[] values = new byte[boundary.length - 1];
+
+                for (int i = 0; i < boundary.length - 1; i++) {
+                    values[i] = (boundary[i] == selStart)
+                                        ? IME_ATTR_TARGET_CONVERTED
+                                        : IME_ATTR_CONVERTED;
+                }
+
+                notifyInputMethod(str, boundary, boundary, values, 0, cursor, 0);
+            } else {
             notifyInputMethod(str, null, attBounds, atts, 0, cursor, 0);
         }
     }
+    }
 }
 
< prev index next >