changeset 140:fbbfe5a37fa1

RT-18455: TextField, TextArea: Incorrect MacOS key bindings
author leifs
date Fri, 09 Dec 2011 13:23:26 -0800
parents 0c5ec026b7ad
children b094b6a7ca18 3878bc13268c
files javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java
diffstat 4 files changed, 75 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Fri Dec 09 16:53:06 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Fri Dec 09 13:23:26 2011 -0800
@@ -76,19 +76,29 @@
             TEXT_AREA_BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED, "LineStart").meta()); // changed
             TEXT_AREA_BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED, "LineEnd").meta()); // changed
             TEXT_AREA_BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED, "LineEnd").meta()); // changed
-            TEXT_AREA_BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED, "SelectLineStart").shift().meta()); // changed
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED, "SelectLineStart").shift().meta()); // changed
-            TEXT_AREA_BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED, "SelectLineEnd").shift().meta()); // changed
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED, "SelectLineEnd").shift().meta()); // changed
+            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "Home").meta());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "Home").meta());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "End").meta());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "End").meta());
 
-            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "ParagraphStart").meta());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "ParagraphStart").meta());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "ParagraphEnd").meta());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "ParagraphEnd").meta());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "SelectParagraphStart").meta().shift());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "SelectParagraphStart").meta().shift());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "SelectParagraphEnd").meta().shift());
-            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "SelectParagraphEnd").meta().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED, "SelectLineStartExtend").shift().meta()); // changed
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED, "SelectLineStartExtend").shift().meta()); // changed
+            TEXT_AREA_BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED, "SelectLineEndExtend").shift().meta()); // changed
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED, "SelectLineEndExtend").shift().meta()); // changed
+            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "SelectHomeExtend").meta().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "SelectHomeExtend").meta().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "SelectEndExtend").meta().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "SelectEndExtend").meta().shift());
+
+            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "ParagraphStart").alt());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "ParagraphStart").alt());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "ParagraphEnd").alt());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "ParagraphEnd").alt());
+
+            TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "SelectParagraphStart").alt().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "SelectParagraphStart").alt().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED, "SelectParagraphEnd").alt().shift());
+            TEXT_AREA_BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED, "SelectParagraphEnd").alt().shift());
         } else {
             TEXT_AREA_BINDINGS.add(new KeyBinding(UP, KEY_PRESSED, "ParagraphStart").ctrl());
             TEXT_AREA_BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED, "ParagraphStart").ctrl());
@@ -152,10 +162,12 @@
         if (textInputControl.isEditable()) {
 //            fnCaretAnim(false);
 //            setCaretOpacity(1.0);
-            if ("LineStart".equals(name)) skin.lineStart(false);
-            else if ("LineEnd".equals(name)) skin.lineEnd(false);
-            else if ("SelectLineStart".equals(name)) skin.lineStart(true);
-            else if ("SelectLineEnd".equals(name)) skin.lineEnd(true);
+            if ("LineStart".equals(name)) skin.lineStart(false, false);
+            else if ("LineEnd".equals(name)) skin.lineEnd(false, false);
+            else if ("SelectLineStart".equals(name)) skin.lineStart(true, false);
+            else if ("SelectLineStartExtend".equals(name)) skin.lineStart(true, true);
+            else if ("SelectLineEnd".equals(name)) skin.lineEnd(true, false);
+            else if ("SelectLineEndExtend".equals(name)) skin.lineEnd(true, true);
             else if ("PreviousLine".equals(name)) skin.previousLine(false);
             else if ("NextLine".equals(name)) skin.nextLine(false);
             else if ("SelectPreviousLine".equals(name)) skin.previousLine(true);
@@ -257,7 +269,7 @@
                     // to indicate the text can be dragged, etc.
                 } else if (!(e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown())) {
                     switch (e.getClickCount()) {
-                      case 1: skin.positionCaret(hit, false); break;
+                      case 1: skin.positionCaret(hit, false, false); break;
                       case 2: mouseDoubleClick(hit); break;
                       case 3: mouseTripleClick(hit); break;
                     }
@@ -273,7 +285,7 @@
                     if(macOS) {
                         textArea.extendSelection(i);
                     } else {
-                        skin.positionCaret(hit, true);
+                        skin.positionCaret(hit, true, false);
                     }
                 }
 //                 skin.setForwardBias(hit.isLeading());
@@ -290,7 +302,7 @@
         if (!textArea.isDisabled() && !deferClick) {
             if (e.getButton() == MouseButton.PRIMARY && !(e.isMiddleButtonDown() || e.isSecondaryButtonDown())) {
                 if (!(e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown())) {
-                    skin.positionCaret(skin.getIndex(e), true);
+                    skin.positionCaret(skin.getIndex(e), true, false);
                 }
             }
         }
@@ -305,7 +317,7 @@
             setCaretAnimating(false);
             if (deferClick) {
                 deferClick = false;
-                skin.positionCaret(skin.getIndex(e), shiftDown);
+                skin.positionCaret(skin.getIndex(e), shiftDown, false);
                 shiftDown = false;
             }
             setCaretAnimating(true);
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Fri Dec 09 16:53:06 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Fri Dec 09 13:23:26 2011 -0800
@@ -134,6 +134,8 @@
             else if ("Unselect".equals(name)) textInputControl.deselect();
             else if ("SelectHome".equals(name)) selectHome();
             else if ("SelectEnd".equals(name)) selectEnd();
+            else if ("SelectHomeExtend".equals(name)) selectHomeExtend();
+            else if ("SelectEndExtend".equals(name)) selectEndExtend();
             else super.callAction(name);
             setCaretAnimating(true);
         } else if ("Copy".equals(name)) {
@@ -226,20 +228,19 @@
     protected void fire(KeyEvent event) { } // TODO move to TextFieldBehavior
 
     private void selectHome() {
-        TextInputControl textInputControl = getControl();
-        if (macOS) {
-            textInputControl.extendSelection(0);
-        } else {
-            textInputControl.selectHome();
-        }
+        getControl().selectHome();
     }
 
     private void selectEnd() {
+        getControl().selectEnd();
+    }
+
+    private void selectHomeExtend() {
+        getControl().extendSelection(0);
+    }
+
+    private void selectEndExtend() {
         TextInputControl textInputControl = getControl();
-        if (macOS) {
-            textInputControl.extendSelection(textInputControl.getLength());
-        } else {
-            textInputControl.selectEnd();
-        }
+        textInputControl.extendSelection(textInputControl.getLength());
     }
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java	Fri Dec 09 16:53:06 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java	Fri Dec 09 13:23:26 2011 -0800
@@ -51,7 +51,6 @@
         BINDINGS.add(new KeyBinding(ENTER, KEY_PRESSED,       "Fire"));
         // deletion
         BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED,  "DeletePreviousChar"));
-        BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED,  "DeletePreviousChar").shift());
         BINDINGS.add(new KeyBinding(DELETE, KEY_PRESSED,      "DeleteNextChar"));
         // cut/copy/paste
         BINDINGS.add(new KeyBinding(CUT, KEY_PRESSED,         "Cut"));
@@ -66,13 +65,17 @@
         BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED,     "SelectBackward").shift());
         BINDINGS.add(new KeyBinding(UP, KEY_PRESSED,          "SelectHome").shift());
         BINDINGS.add(new KeyBinding(KP_UP, KEY_PRESSED,       "SelectHome").shift());
-        BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,        "SelectHome").shift());
         BINDINGS.add(new KeyBinding(DOWN, KEY_PRESSED,        "SelectEnd").shift());
         BINDINGS.add(new KeyBinding(KP_DOWN, KEY_PRESSED,     "SelectEnd").shift());
-        BINDINGS.add(new KeyBinding(END, KEY_PRESSED,         "SelectEnd").shift());
+
+        BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED,  "DeletePreviousChar").shift());
+        BINDINGS.add(new KeyBinding(DELETE, KEY_PRESSED,      "DeleteNextChar").shift());
 
         // platform specific settings
         if (PlatformUtil.isMac()) {
+            BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,       "SelectHomeExtend").shift());
+            BINDINGS.add(new KeyBinding(END, KEY_PRESSED,        "SelectEndExtend").shift());
+
             BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,       "Home").meta());
             BINDINGS.add(new KeyBinding(END, KEY_PRESSED,        "End").meta());
             BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED,       "Home").meta());
@@ -89,17 +92,19 @@
             BINDINGS.add(new KeyBinding(V, KEY_PRESSED,          "Paste").meta());
             BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,       "SelectHome").shift().meta());
             BINDINGS.add(new KeyBinding(END, KEY_PRESSED,        "SelectEnd").shift().meta());
-            BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED,       "SelectHome").shift().meta());
-            BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED,    "SelectHome").shift().meta());
-            BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED,      "SelectEnd").shift().meta());
-            BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED,   "SelectEnd").shift().meta());
+            BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED,       "SelectHomeExtend").shift().meta());
+            BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED,    "SelectHomeExtend").shift().meta());
+            BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED,      "SelectEndExtend").shift().meta());
+            BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED,   "SelectEndExtend").shift().meta());
             BINDINGS.add(new KeyBinding(A, KEY_PRESSED,          "SelectAll").meta());
-            BINDINGS.add(new KeyBinding(BACK_SLASH, KEY_PRESSED, "UnSelect").meta());
             BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED,       "SelectPreviousWord").shift().alt());
             BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED,    "SelectPreviousWord").shift().alt());
             BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED,      "SelectNextWord").shift().alt());
             BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED,   "SelectNextWord").shift().alt());
         } else {
+            BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,       "SelectHome").shift());
+            BINDINGS.add(new KeyBinding(END, KEY_PRESSED,        "SelectEnd").shift());
+
             BINDINGS.add(new KeyBinding(HOME, KEY_PRESSED,       "Home").ctrl());
             BINDINGS.add(new KeyBinding(END, KEY_PRESSED,        "End").ctrl());
             BINDINGS.add(new KeyBinding(LEFT, KEY_PRESSED,       "PreviousWord").ctrl());
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java	Fri Dec 09 16:53:06 2011 +1000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextAreaSkin.java	Fri Dec 09 13:23:26 2011 -0800
@@ -593,7 +593,7 @@
         return index;
     }
 
-    public void positionCaret(HitInfo hit, boolean select) {
+    public void positionCaret(HitInfo hit, boolean select, boolean extendSelection) {
         int pos = hit.getInsertionIndex();
         boolean isNewLine =
                (pos > 0 &&
@@ -607,7 +607,11 @@
         }
 
         if (select) {
-            getSkinnable().selectPositionCaret(pos);
+            if (extendSelection) {
+                getSkinnable().extendSelection(pos);
+            } else {
+                getSkinnable().selectPositionCaret(pos);
+            }
         } else {
             getSkinnable().positionCaret(pos);
         }
@@ -845,7 +849,7 @@
      */
     double targetCaretX = -1;
 
-    protected void downLines(int nLines, boolean select) {
+    protected void downLines(int nLines, boolean select, boolean extendSelection) {
         Text textNode = getTextNode();
         Bounds caretBounds = caretPath.getLayoutBounds();
         double midY = (caretBounds.getMinY() + caretBounds.getMaxY()) / 2 + nLines * fontMetrics.get().getLineHeight();
@@ -862,36 +866,38 @@
                 hit.setCharIndex(pos - 1);
             }
         }
-        positionCaret(hit, select);
+        positionCaret(hit, select, extendSelection);
         targetCaretX = x;
     }
 
     public void previousLine(boolean select) {
-        downLines(-1, select);
+        downLines(-1, select, false);
     }
 
     public void nextLine(boolean select) {
-        downLines(1, select);
+        downLines(1, select, false);
     }
 
     public void previousPage(boolean select) {
-        downLines(-(int)(scrollPane.getViewportBounds().getHeight() / fontMetrics.get().getLineHeight()), select);
+        downLines(-(int)(scrollPane.getViewportBounds().getHeight() / fontMetrics.get().getLineHeight()),
+                  select, false);
     }
 
     public void nextPage(boolean select) {
-        downLines((int)(scrollPane.getViewportBounds().getHeight() / fontMetrics.get().getLineHeight()), select);
+        downLines((int)(scrollPane.getViewportBounds().getHeight() / fontMetrics.get().getLineHeight()),
+                  select, false);
     }
 
-    public void lineStart(boolean select) {
+    public void lineStart(boolean select, boolean extendSelection) {
         Bounds caretBounds = caretPath.getLayoutBounds();
         double midY = (caretBounds.getMinY() + caretBounds.getMaxY()) / 2;
         HitInfo hit = getTextNode().impl_hitTestChar(translateCaretPosition(new Point2D(getTextLeft(), midY)));
-        positionCaret(hit, select);
+        positionCaret(hit, select, extendSelection);
     }
 
-    public void lineEnd(boolean select) {
+    public void lineEnd(boolean select, boolean extendSelection) {
         targetCaretX = Double.MAX_VALUE;
-        downLines(0, select);
+        downLines(0, select, extendSelection);
         targetCaretX = -1;
     }