changeset 6533:37b60b405b4b

RT-32459: CMD-BACKSPACE should delete the line to the left of the caret, not the word (Mac)
author leifs
date Fri, 21 Mar 2014 10:04:53 -0700
parents 74b46ab976e2
children 8a9062f8c637
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java
diffstat 4 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Fri Mar 21 10:56:14 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Fri Mar 21 10:04:53 2014 -0700
@@ -280,6 +280,20 @@
         skin.deleteChar(previous);
     }
 
+    @Override protected void deleteFromLineStart() {
+        TextArea textArea = getControl();
+        int end = textArea.getCaretPosition();
+
+        if (end > 0) {
+            lineStart(false, false);
+            int start = textArea.getCaretPosition();
+            if (end > start) {
+                getUndoManager().addChange(start, textArea.textProperty().getValueSafe().substring(start, end), null);
+                replaceText(start, end, "");
+            }
+        }
+    }
+
     private void lineStart(boolean select, boolean extendSelection) {
         skin.lineStart(select, extendSelection);
     }
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Fri Mar 21 10:56:14 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Fri Mar 21 10:04:53 2014 -0700
@@ -200,6 +200,16 @@
         skin.replaceText(start, end, txt);
     }
 
+    @Override protected void deleteFromLineStart() {
+        TextField textField = getControl();
+        int end = textField.getCaretPosition();
+
+        if (end > 0) {
+            getUndoManager().addChange(0, textField.textProperty().getValueSafe().substring(0, end), null);
+            replaceText(0, end, "");
+        }
+    }
+
     @Override protected void setCaretAnimating(boolean play) {
         if (skin != null) {
             skin.setCaretAnimating(play);
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Fri Mar 21 10:56:14 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Fri Mar 21 10:04:53 2014 -0700
@@ -118,6 +118,7 @@
     protected abstract void deleteChar(boolean previous);
     protected abstract void replaceText(int start, int end, String txt);
     protected abstract void setCaretAnimating(boolean play);
+    protected abstract void deleteFromLineStart();
 
     protected void scrollCharacterToVisible(int index) {
         // TODO this method should be removed when TextAreaSkin
@@ -149,6 +150,7 @@
             if ("InputCharacter".equals(name)) defaultKeyTyped(lastEvent);
             else if ("Cut".equals(name)) cut();
             else if ("Paste".equals(name)) paste();
+            else if ("DeleteFromLineStart".equals(name)) deleteFromLineStart();
             else if ("DeletePreviousChar".equals(name)) deletePreviousChar();
             else if ("DeleteNextChar".equals(name)) deleteNextChar();
             else if ("DeletePreviousWord".equals(name)) deletePreviousWord();
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java	Fri Mar 21 10:56:14 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextInputControlBindings.java	Fri Mar 21 10:04:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,8 +89,9 @@
             BINDINGS.add(new KeyBinding(KP_LEFT, KEY_PRESSED,    "LeftWord").alt());
             BINDINGS.add(new KeyBinding(RIGHT, KEY_PRESSED,      "RightWord").alt());
             BINDINGS.add(new KeyBinding(KP_RIGHT, KEY_PRESSED,   "RightWord").alt());
-            BINDINGS.add(new KeyBinding(DELETE, KEY_PRESSED,     "DeleteNextWord").shortcut());
-            BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED, "DeletePreviousWord").shortcut());
+            BINDINGS.add(new KeyBinding(DELETE, KEY_PRESSED,     "DeleteNextWord").alt());
+            BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED, "DeletePreviousWord").alt());
+            BINDINGS.add(new KeyBinding(BACK_SPACE, KEY_PRESSED, "DeleteFromLineStart").shortcut());
             BINDINGS.add(new KeyBinding(X, KEY_PRESSED,          "Cut").shortcut());
             BINDINGS.add(new KeyBinding(C, KEY_PRESSED,          "Copy").shortcut());
             BINDINGS.add(new KeyBinding(INSERT, KEY_PRESSED,     "Copy").shortcut());