-
-
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.
Implement Emacs key bindings (#6037)
Co-authored-by: Felix Luthman <34520175+felixlut@users.noreply.github.com> Co-authored-by: Tommy Samuelsson <Zodbigt@users.noreply.github.com> Co-authored-by: muachilin <32566798+muachilin@users.noreply.github.com> Co-authored-by: Kristoffer Gunnarsson <kristoffergunnarsson47@gmail.com> Co-authored-by: David Stevens <dstevens@kth.se> Co-authored-by: Carl Christian Snethlage <cc.snethlage@gmail.com>
- Loading branch information
1 parent
cc1bb83
commit 82e555d
Showing
18 changed files
with
735 additions
and
37 deletions.
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
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
113 changes: 113 additions & 0 deletions
113
src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.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,113 @@ | ||
package org.jabref.gui.keyboard; | ||
|
||
import javafx.scene.input.KeyEvent; | ||
|
||
import org.jabref.gui.Globals; | ||
import org.jabref.logic.util.strings.StringManipulator; | ||
import org.jabref.model.util.ResultingStringState; | ||
|
||
import org.fxmisc.richtext.CodeArea; | ||
import org.fxmisc.richtext.NavigationActions; | ||
|
||
public class CodeAreaKeyBindings { | ||
|
||
public static void call(CodeArea codeArea, KeyEvent event) { | ||
KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs(); | ||
keyBindingRepository.mapToKeyBinding(event).ifPresent(binding -> { | ||
switch (binding) { | ||
case EDITOR_DELETE -> { | ||
codeArea.deleteNextChar(); | ||
event.consume(); | ||
} | ||
case EDITOR_BACKWARD -> { | ||
codeArea.previousChar(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_FORWARD -> { | ||
codeArea.nextChar(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_WORD_BACKWARD -> { | ||
codeArea.wordBreaksBackwards(2, NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_WORD_FORWARD -> { | ||
codeArea.wordBreaksForwards(2, NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_BEGINNING_DOC -> { | ||
codeArea.start(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_UP -> { | ||
codeArea.paragraphStart(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_BEGINNING -> { | ||
codeArea.lineStart(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_END_DOC -> { | ||
codeArea.end(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_DOWN -> { | ||
codeArea.paragraphEnd(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_END -> { | ||
codeArea.lineEnd(NavigationActions.SelectionPolicy.CLEAR); | ||
event.consume(); | ||
} | ||
case EDITOR_CAPITALIZE -> { | ||
int pos = codeArea.getCaretPosition(); | ||
String text = codeArea.getText(0, codeArea.getText().length()); | ||
ResultingStringState res = StringManipulator.capitalize(pos, text); | ||
codeArea.replaceText(res.text); | ||
codeArea.displaceCaret(res.caretPosition); | ||
event.consume(); | ||
} | ||
case EDITOR_LOWERCASE -> { | ||
int pos = codeArea.getCaretPosition(); | ||
String text = codeArea.getText(0, codeArea.getText().length()); | ||
ResultingStringState res = StringManipulator.lowercase(pos, text); | ||
codeArea.replaceText(res.text); | ||
codeArea.displaceCaret(res.caretPosition); | ||
event.consume(); | ||
} | ||
case EDITOR_UPPERCASE -> { | ||
int pos = codeArea.getCaretPosition(); | ||
String text = codeArea.getText(0, codeArea.getText().length()); | ||
ResultingStringState res = StringManipulator.uppercase(pos, text); | ||
codeArea.clear(); | ||
codeArea.replaceText(res.text); | ||
codeArea.displaceCaret(res.caretPosition); | ||
event.consume(); | ||
} | ||
case EDITOR_KILL_LINE -> { | ||
int pos = codeArea.getCaretPosition(); | ||
codeArea.replaceText(codeArea.getText(0, pos)); | ||
codeArea.displaceCaret(pos); | ||
event.consume(); | ||
} | ||
case EDITOR_KILL_WORD -> { | ||
int pos = codeArea.getCaretPosition(); | ||
String text = codeArea.getText(0, codeArea.getText().length()); | ||
ResultingStringState res = StringManipulator.killWord(pos, text); | ||
codeArea.replaceText(res.text); | ||
codeArea.displaceCaret(res.caretPosition); | ||
event.consume(); | ||
} | ||
case EDITOR_KILL_WORD_BACKWARD -> { | ||
int pos = codeArea.getCaretPosition(); | ||
String text = codeArea.getText(0, codeArea.getText().length()); | ||
ResultingStringState res = StringManipulator.backwardKillWord(pos, text); | ||
codeArea.replaceText(res.text); | ||
codeArea.displaceCaret(res.caretPosition); | ||
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
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.