R4.9: ElyMark menus and keys as Typora's, component pin 6b033f3

Paragraph and Format menus with Typora's items, labels and keys; Table
is a Paragraph submenu with row and column moves and source tidy.
Ctrl+/ toggles source, F8 focus, F9 typewriter, Ctrl+Shift+=/-/0 size,
Ctrl+Shift+C copies as Markdown, Ctrl+Shift+V pastes as plain text.
Refused commands show why, including refusals read in the background.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-14 16:38:28 -04:00
1 parent 4252ff5062
commit 539206297c
20 files changed
+963 -153

No files matched your search

+65 -56
View File
@@ -1,14 +1,10 @@
//! The table menu's work on the shown file (MARK-06).
use ely_gpui_component::{
documents::{TableEdit, TableRefusal},
primitives::Severity,
};
use ely_office::prelude::*;
use ely_ui::i18n::text;
use gpui::{Context, InteractiveElement as _, actions};
use ely_gpui_component::documents::TableEdit;
use ely_ui::{commands, i18n::text};
use gpui::{Action, App, Context, InteractiveElement as _, KeyBinding, Menu, MenuItem, actions};
use crate::desk::Desk;
use crate::{blocks::edits, desk::Desk, keys::item};
actions!(
mark,
@@ -18,58 +14,71 @@ actions!(
RowBelow,
ColumnLeft,
ColumnRight,
MoveRowUp,
MoveRowDown,
MoveColumnLeft,
MoveColumnRight,
DeleteRow,
DeleteColumn
DeleteColumn,
TidyTable
]
);
impl Desk {
fn table(&mut self, edit: Option<TableEdit>, cx: &mut Context<Self>) {
let Some(view) = self.active_view() else {
let said = text(cx, "command.blocked.no_document", &[]);
return self.toast(said, Severity::Warning, cx);
};
let document = view.read(cx).document().clone();
let done = document.update(cx, |document, cx| match edit {
Some(edit) => document.edit_table(edit, cx),
None => document.insert_table(cx),
});
let Err(refusal) = done else {
return;
};
let key = match refusal {
TableRefusal::Outside => "mark.table.none",
TableRefusal::Kept => "mark.table.kept",
TableRefusal::Beyond => "mark.table.beyond",
TableRefusal::Mixed => "mark.table.mixed",
TableRefusal::Preview => "mark.preview.read_only",
};
let said = text(cx, key, &[]);
self.toast(said, Severity::Info, cx);
}
pub fn bind(cx: &mut App) {
let at = Some(commands::CONTEXT);
// An open block's input takes Ctrl+Enter as Submit.
let open = Some("MarkdownDocument > ElyInput");
cx.bind_keys([
KeyBinding::new("secondary-t", InsertTable, at),
KeyBinding::new("secondary-enter", RowBelow, at),
KeyBinding::new("secondary-enter", RowBelow, open),
KeyBinding::new("alt-up", MoveRowUp, at),
KeyBinding::new("alt-down", MoveRowDown, at),
KeyBinding::new("alt-left", MoveColumnLeft, at),
KeyBinding::new("alt-right", MoveColumnRight, at),
KeyBinding::new("secondary-shift-backspace", DeleteRow, at),
]);
}
pub fn table_actions(element: gpui::Div, cx: &mut Context<Self>) -> gpui::Div {
element
.on_action(cx.listener(|desk, _: &InsertTable, _, cx| desk.table(None, cx)))
.on_action(
cx.listener(|desk, _: &RowAbove, _, cx| desk.table(Some(TableEdit::RowAbove), cx)),
)
.on_action(
cx.listener(|desk, _: &RowBelow, _, cx| desk.table(Some(TableEdit::RowBelow), cx)),
)
.on_action(cx.listener(|desk, _: &ColumnLeft, _, cx| {
desk.table(Some(TableEdit::ColumnLeft), cx)
}))
.on_action(cx.listener(|desk, _: &ColumnRight, _, cx| {
desk.table(Some(TableEdit::ColumnRight), cx)
}))
.on_action(
cx.listener(|desk, _: &DeleteRow, _, cx| {
desk.table(Some(TableEdit::DeleteRow), cx)
}),
)
.on_action(cx.listener(|desk, _: &DeleteColumn, _, cx| {
desk.table(Some(TableEdit::DeleteColumn), cx)
}))
/// Typora's Paragraph ▸ Table.
pub fn table_menu(cx: &App) -> Menu {
let item = |key: &str, action: Box<dyn Action>| item(key, action, cx);
Menu::new(text(cx, "mark.menu.table", &[])).items([
item("mark.table.insert", Box::new(InsertTable)),
MenuItem::separator(),
item("mark.table.row_above", Box::new(RowAbove)),
item("mark.table.row_below", Box::new(RowBelow)),
item("mark.table.column_left", Box::new(ColumnLeft)),
item("mark.table.column_right", Box::new(ColumnRight)),
MenuItem::separator(),
item("mark.table.move_row_up", Box::new(MoveRowUp)),
item("mark.table.move_row_down", Box::new(MoveRowDown)),
item("mark.table.move_column_left", Box::new(MoveColumnLeft)),
item("mark.table.move_column_right", Box::new(MoveColumnRight)),
MenuItem::separator(),
item("mark.table.delete_row", Box::new(DeleteRow)),
item("mark.table.delete_column", Box::new(DeleteColumn)),
MenuItem::separator(),
item("mark.table.tidy", Box::new(TidyTable)),
])
}
impl Desk {
pub fn table_actions(root: gpui::Div, cx: &mut Context<Self>) -> gpui::Div {
use TableEdit as T;
edits!(root, cx,
InsertTable => |d, cx| d.insert_table(cx),
RowAbove => |d, cx| d.edit_table(T::RowAbove, cx),
RowBelow => |d, cx| d.edit_table(T::RowBelow, cx),
ColumnLeft => |d, cx| d.edit_table(T::ColumnLeft, cx),
ColumnRight => |d, cx| d.edit_table(T::ColumnRight, cx),
MoveRowUp => |d, cx| d.edit_table(T::MoveRowUp, cx),
MoveRowDown => |d, cx| d.edit_table(T::MoveRowDown, cx),
MoveColumnLeft => |d, cx| d.edit_table(T::MoveColumnLeft, cx),
MoveColumnRight => |d, cx| d.edit_table(T::MoveColumnRight, cx),
DeleteRow => |d, cx| d.edit_table(T::DeleteRow, cx),
DeleteColumn => |d, cx| d.edit_table(T::DeleteColumn, cx),
TidyTable => |d, cx| d.edit_table(T::Tidy, cx),
)
}
}