-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emacs style key bindings are re-added to JabRef through the preferences menu. The supported key bindings have feature parity with the previous implementation in JabRef v<4, and additionally support any class that extends TextInputControl. In practice, this means that the new implementation supports both TextFields and TextAreas by default. Some functionality may still be missing Co-authored-by: Felix Luthman <[email protected]> Co-authored-by: Tommy Samuelsson <[email protected]> Co-authored-by: muachilin <[email protected]> Co-authored-by: Kristoffer Gunnarsson <[email protected]>
- Loading branch information
1 parent
cc94cca
commit 1d68c6e
Showing
11 changed files
with
528 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.jabref.gui.keyboard; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.scene.Scene; | ||
import javafx.scene.control.TextInputControl; | ||
import javafx.scene.input.KeyEvent; | ||
|
||
import org.jabref.Globals; | ||
import org.jabref.logic.util.strings.EmacsStringManipulator; | ||
import org.jabref.model.util.ResultingEmacsState; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
public class EmacsKeyBindings { | ||
|
||
public static void executeEmacs(Scene scene, KeyEvent event) { | ||
boolean EmacsFlag = Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS); | ||
if (EmacsFlag && scene.focusOwnerProperty().get() instanceof TextInputControl) { | ||
boolean CAFlag = Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CA); | ||
boolean CFFlag = Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CF); | ||
boolean CNFlag = Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CN); | ||
boolean AUFlag = Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_AU); | ||
|
||
KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs(); | ||
TextInputControl focusedTextField = (TextInputControl) scene.focusOwnerProperty().get(); | ||
Optional<KeyBinding> keyBinding = keyBindingRepository.mapToKeyBinding(event); | ||
if (keyBinding.isPresent()) { | ||
if (keyBinding.get().equals(KeyBinding.EMACS_DELETE)) { | ||
focusedTextField.deletePreviousChar(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_BACKWARD)) { | ||
focusedTextField.backward(); | ||
event.consume(); | ||
} else if (CFFlag && keyBinding.get().equals(KeyBinding.EMACS_FORWARD)) { | ||
focusedTextField.forward(); | ||
event.consume(); | ||
} else if (CAFlag && keyBinding.get().equals(KeyBinding.EMACS_BEGINNING)) { | ||
focusedTextField.home(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_END)) { | ||
focusedTextField.end(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_BEGINNING_DOC)) { | ||
focusedTextField.home(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_END_DOC)) { | ||
focusedTextField.end(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_UP)) { | ||
focusedTextField.home(); | ||
event.consume(); | ||
} else if (CNFlag && keyBinding.get().equals(KeyBinding.EMACS_DOWN)) { | ||
focusedTextField.end(); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_CAPITALIZE)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
String text = focusedTextField.getText(0, focusedTextField.getText().length()); | ||
ResultingEmacsState res = EmacsStringManipulator.capitalize(pos, text); | ||
focusedTextField.setText(res.text); | ||
focusedTextField.positionCaret(res.caretPos); | ||
event.consume(); | ||
} | ||
else if (keyBinding.get().equals(KeyBinding.EMACS_LOWERCASE)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
String text = focusedTextField.getText(0, focusedTextField.getText().length()); | ||
ResultingEmacsState res = EmacsStringManipulator.lowercase(pos, text); | ||
focusedTextField.setText(res.text); | ||
focusedTextField.positionCaret(res.caretPos); | ||
event.consume(); | ||
} | ||
else if (AUFlag && keyBinding.get().equals(KeyBinding.EMACS_UPPERCASE)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
String text = focusedTextField.getText(0, focusedTextField.getText().length()); | ||
ResultingEmacsState res = EmacsStringManipulator.uppercase(pos, text); | ||
focusedTextField.setText(res.text); | ||
focusedTextField.positionCaret(res.caretPos); | ||
event.consume(); | ||
} | ||
else if (keyBinding.get().equals(KeyBinding.EMACS_KILLLINE)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
focusedTextField.setText(focusedTextField.getText(0, pos)); | ||
focusedTextField.positionCaret(pos); | ||
event.consume(); | ||
} else if (keyBinding.get().equals(KeyBinding.EMACS_KILLWORD)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
String text = focusedTextField.getText(0, focusedTextField.getText().length()); | ||
ResultingEmacsState res = EmacsStringManipulator.killWord(pos, text); | ||
focusedTextField.setText(res.text); | ||
focusedTextField.positionCaret(res.caretPos); | ||
event.consume(); | ||
} | ||
else if (keyBinding.get().equals(KeyBinding.EMACS_BACKWARDKILLWORD)) { | ||
int pos = focusedTextField.getCaretPosition(); | ||
String text = focusedTextField.getText(0, focusedTextField.getText().length()); | ||
ResultingEmacsState res = EmacsStringManipulator.backwardKillWord(pos, text); | ||
focusedTextField.setText(res.text); | ||
focusedTextField.positionCaret(res.caretPos); | ||
event.consume(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.