use gpui::{App, KeyBinding, actions};
use crate::editor::{CONTEXT, image};
actions!(
bezel_editor,
[
Backspace,
Delete,
KillLine,
DeleteWordLeft,
DeleteWordRight,
DeleteToHome,
Left,
Right,
Up,
Down,
Home,
End,
SelectLeft,
SelectRight,
SelectUp,
SelectDown,
SelectHome,
SelectEnd,
SelectAll,
WordLeft,
WordRight,
SelectWordLeft,
SelectWordRight,
SplitBlock,
Indent,
Outdent,
Dismiss,
Copy,
Cut,
Paste,
Undo,
Redo,
ToggleBold,
ToggleItalic,
ToggleStrike,
ToggleCode,
MoveBlockUp,
MoveBlockDown,
DuplicateBlock,
RemoveBlock,
ConfirmUrl,
CancelUrl,
IncreaseTextSize,
DecreaseTextSize,
ResetTextSize,
]
);
pub fn init(cx: &mut App) {
cx.bind_keys(bindings());
}
pub fn bindings() -> Vec<KeyBinding> {
let ctx = Some(CONTEXT);
let mut bindings = Vec::new();
bindings.extend([
KeyBinding::new("backspace", Backspace, ctx),
KeyBinding::new("delete", Delete, ctx),
KeyBinding::new("left", Left, ctx),
KeyBinding::new("right", Right, ctx),
KeyBinding::new("up", Up, ctx),
KeyBinding::new("down", Down, ctx),
KeyBinding::new("home", Home, ctx),
KeyBinding::new("end", End, ctx),
KeyBinding::new("shift-left", SelectLeft, ctx),
KeyBinding::new("shift-right", SelectRight, ctx),
KeyBinding::new("shift-up", SelectUp, ctx),
KeyBinding::new("shift-down", SelectDown, ctx),
KeyBinding::new("shift-home", SelectHome, ctx),
KeyBinding::new("shift-end", SelectEnd, ctx),
KeyBinding::new("enter", SplitBlock, ctx),
KeyBinding::new("tab", Indent, ctx),
KeyBinding::new("shift-tab", Outdent, ctx),
KeyBinding::new("escape", Dismiss, ctx),
]);
let prompt = Some(image::PROMPT_CONTEXT);
bindings.extend([
KeyBinding::new("enter", ConfirmUrl, prompt),
KeyBinding::new("escape", CancelUrl, prompt),
]);
#[cfg(target_os = "macos")]
bindings.extend([
KeyBinding::new("cmd-a", SelectAll, ctx),
KeyBinding::new("cmd-c", Copy, ctx),
KeyBinding::new("cmd-x", Cut, ctx),
KeyBinding::new("cmd-v", Paste, ctx),
KeyBinding::new("cmd-z", Undo, ctx),
KeyBinding::new("cmd-shift-z", Redo, ctx),
KeyBinding::new("cmd-b", ToggleBold, ctx),
KeyBinding::new("cmd-i", ToggleItalic, ctx),
KeyBinding::new("cmd-e", ToggleCode, ctx),
KeyBinding::new("cmd-shift-x", ToggleStrike, ctx),
KeyBinding::new("cmd-=", IncreaseTextSize, ctx),
KeyBinding::new("cmd-+", IncreaseTextSize, ctx),
KeyBinding::new("cmd-shift-=", IncreaseTextSize, ctx),
KeyBinding::new("cmd--", DecreaseTextSize, ctx),
KeyBinding::new("cmd-0", ResetTextSize, ctx),
KeyBinding::new("cmd-left", Home, ctx),
KeyBinding::new("cmd-right", End, ctx),
KeyBinding::new("cmd-shift-left", SelectHome, ctx),
KeyBinding::new("cmd-shift-right", SelectEnd, ctx),
KeyBinding::new("alt-left", WordLeft, ctx),
KeyBinding::new("alt-right", WordRight, ctx),
KeyBinding::new("alt-shift-left", SelectWordLeft, ctx),
KeyBinding::new("alt-shift-right", SelectWordRight, ctx),
KeyBinding::new("ctrl-a", Home, ctx),
KeyBinding::new("ctrl-e", End, ctx),
KeyBinding::new("ctrl-b", Left, ctx),
KeyBinding::new("ctrl-f", Right, ctx),
KeyBinding::new("ctrl-n", Down, ctx),
KeyBinding::new("ctrl-p", Up, ctx),
KeyBinding::new("ctrl-h", Backspace, ctx),
KeyBinding::new("ctrl-d", Delete, ctx),
KeyBinding::new("ctrl-k", KillLine, ctx),
KeyBinding::new("alt-backspace", DeleteWordLeft, ctx),
KeyBinding::new("alt-delete", DeleteWordRight, ctx),
KeyBinding::new("cmd-backspace", DeleteToHome, ctx),
]);
#[cfg(not(target_os = "macos"))]
bindings.extend([
KeyBinding::new("ctrl-a", SelectAll, ctx),
KeyBinding::new("ctrl-c", Copy, ctx),
KeyBinding::new("ctrl-x", Cut, ctx),
KeyBinding::new("ctrl-v", Paste, ctx),
KeyBinding::new("ctrl-z", Undo, ctx),
KeyBinding::new("ctrl-shift-z", Redo, ctx),
KeyBinding::new("ctrl-y", Redo, ctx),
KeyBinding::new("ctrl-b", ToggleBold, ctx),
KeyBinding::new("ctrl-i", ToggleItalic, ctx),
KeyBinding::new("ctrl-e", ToggleCode, ctx),
KeyBinding::new("ctrl-shift-x", ToggleStrike, ctx),
KeyBinding::new("ctrl-=", IncreaseTextSize, ctx),
KeyBinding::new("ctrl-+", IncreaseTextSize, ctx),
KeyBinding::new("ctrl-shift-=", IncreaseTextSize, ctx),
KeyBinding::new("ctrl--", DecreaseTextSize, ctx),
KeyBinding::new("ctrl-0", ResetTextSize, ctx),
KeyBinding::new("ctrl-left", WordLeft, ctx),
KeyBinding::new("ctrl-right", WordRight, ctx),
KeyBinding::new("ctrl-shift-left", SelectWordLeft, ctx),
KeyBinding::new("ctrl-shift-right", SelectWordRight, ctx),
KeyBinding::new("ctrl-backspace", DeleteWordLeft, ctx),
KeyBinding::new("ctrl-delete", DeleteWordRight, ctx),
]);
bindings
}