Description
FlatLaf provides excellent macOS-native key bindings for text components, including:
alt BACK_SPACE → delete-previous-word
meta LEFT / meta RIGHT → beginLineAction / endLineAction
shift meta LEFT / shift meta RIGHT → select to line boundaries
However, meta BACK_SPACE (Cmd+Backspace) → "delete to beginning of line" is missing. This is a standard Cocoa/NSTextField behavior that macOS users expect in text fields.
Note: Apple's own AquaLookAndFeel also does not provide this binding, so this would be an improvement over the system L&F.
Expected behavior
Pressing Cmd+Backspace in a text field on macOS should delete all text from the caret position to the beginning of the current line (same as native macOS text editing in Safari, Notes, TextEdit, etc.).
Current behavior
Nothing happens. The key combination is not bound to any action.
Suggested implementation
- Add
mac("meta BACK_SPACE"), "delete-to-line-start" to text component input maps in FlatInputMaps
- Register a
TextAction that uses Utilities.getRowStart() to find the line start and Document.remove() to delete the text
This would be consistent with the existing macOS key binding set that FlatLaf already provides.
Workaround
Custom TextAction installed per-component via KeyboardFocusManager focus listener:
final int menuMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
final KeyStroke cmdBackspace = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, menuMask);
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("focusOwner", evt -> {
if (!(evt.getNewValue() instanceof JTextComponent)) return;
JTextComponent tc = (JTextComponent) evt.getNewValue();
if (tc.getClientProperty("delete-to-line-start") != null) return;
tc.getInputMap().put(cmdBackspace, "delete-to-line-start");
tc.getActionMap().put("delete-to-line-start", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
JTextComponent comp = (JTextComponent) e.getSource();
if (!comp.isEditable()) return;
try {
int caretPos = comp.getCaretPosition();
int lineStart = Utilities.getRowStart(comp, caretPos);
if (lineStart < caretPos) {
comp.getDocument().remove(lineStart, caretPos - lineStart);
}
} catch (BadLocationException ex) { }
}
});
tc.putClientProperty("delete-to-line-start", Boolean.TRUE);
});
Environment
- FlatLaf version: 3.7
- OS: macOS
- Java: 8+
Description
FlatLaf provides excellent macOS-native key bindings for text components, including:
alt BACK_SPACE→delete-previous-wordmeta LEFT/meta RIGHT→beginLineAction/endLineActionshift meta LEFT/shift meta RIGHT→ select to line boundariesHowever,
meta BACK_SPACE(Cmd+Backspace) → "delete to beginning of line" is missing. This is a standard Cocoa/NSTextField behavior that macOS users expect in text fields.Note: Apple's own
AquaLookAndFeelalso does not provide this binding, so this would be an improvement over the system L&F.Expected behavior
Pressing Cmd+Backspace in a text field on macOS should delete all text from the caret position to the beginning of the current line (same as native macOS text editing in Safari, Notes, TextEdit, etc.).
Current behavior
Nothing happens. The key combination is not bound to any action.
Suggested implementation
mac("meta BACK_SPACE"), "delete-to-line-start"to text component input maps inFlatInputMapsTextActionthat usesUtilities.getRowStart()to find the line start andDocument.remove()to delete the textThis would be consistent with the existing macOS key binding set that FlatLaf already provides.
Workaround
Custom
TextActioninstalled per-component viaKeyboardFocusManagerfocus listener:Environment