--- old/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacView.java 2014-11-13 20:25:28.844977485 +0300 +++ new/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacView.java 2014-11-13 20:25:28.748977484 +0300 @@ -30,6 +30,7 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.Map; +import java.util.TreeSet; /** * MacOSX platform implementation class for View. @@ -118,7 +119,8 @@ _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]; @@ -129,7 +131,30 @@ notifyInputMethod(str, null, attBounds, atts, length, cursor, 0); } else { // all other cases = just an update, update preview text but do not commit it - notifyInputMethod(str, null, attBounds, atts, 0, cursor, 0); + if (selLength > 0 + && str != null && str.length() > 0 + && selStart >= 0 + && selLength + selStart <= str.length()) { + + TreeSet 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); + } } } }