src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java

Print this page

        

@@ -418,11 +418,11 @@
 
     /**
      * Tell the component to commit all of the characters in the string to the current
      * text view. This effectively wipes out any text in progress.
      */
-    synchronized private void insertText(String aString) {
+    synchronized private void insertText(String aString, int replaceStart, int replaceLength) {
         AttributedString attribString = new AttributedString(aString);
 
         // Set locale information on the new string.
         attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());
 

@@ -430,11 +430,12 @@
         InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
                                                       InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                                                       attribString.getIterator(),
                                                       aString.length(),
                                                       theCaret,
-                                                      theCaret);
+                                                      theCaret,
+                                                      replaceStart, replaceStart + replaceLength);
         LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
         fCurrentText = null;
         fCurrentTextAsString = null;
         fCurrentTextLength = 0;
     }

@@ -488,36 +489,10 @@
         }
 
         fCurrentText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, theHighlight, begin, end);
     }
 
-   /* Called from JNI to select the previously typed glyph during press and hold */
-    private void selectPreviousGlyph() {
-        if (fIMContext == null) return; // ???
-        try {
-            LWCToolkit.invokeLater(new Runnable() {
-                public void run() {
-                    final int offset = fIMContext.getInsertPositionOffset();
-                    if (offset < 1) return; // ???
-
-                    if (fAwtFocussedComponent instanceof JTextComponent) {
-                        ((JTextComponent) fAwtFocussedComponent).select(offset - 1, offset);
-                        return;
-                    }
-
-                    if (fAwtFocussedComponent instanceof TextComponent) {
-                        ((TextComponent) fAwtFocussedComponent).select(offset - 1, offset);
-                        return;
-                    }
-                    // TODO: Ideally we want to disable press-and-hold in this case
-                }
-            }, fAwtFocussedComponent);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
     private void selectNextGlyph() {
         if (fIMContext == null || !(fAwtFocussedComponent instanceof JTextComponent)) return;
         try {
             LWCToolkit.invokeLater(new Runnable() {
                 public void run() {

@@ -530,11 +505,11 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
-    private void dispatchText(int selectStart, int selectLength, boolean pressAndHold) {
+    private void dispatchText(int selectStart, int selectLength, int replaceStart, int replaceEnd, boolean pressAndHold) {
         // Nothing to do if we have no text.
         if (fCurrentText == null)
             return;
 
         TextHitInfo theCaret = (selectLength == 0 ? TextHitInfo.beforeOffset(selectStart) : null);

@@ -543,11 +518,12 @@
         InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
                                                       InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                                                       fCurrentText.getIterator(),
                                                       0,
                                                       theCaret,
-                                                      visiblePosition);
+                                                      visiblePosition,
+                                                      replaceStart, replaceStart + replaceEnd);
         LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
 
         if (pressAndHold) selectNextGlyph();
     }