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:
1 parent
4252ff5062
commit
539206297c
20 files changed
+963
-153
No files matched your search
@@ -0,0 +1,56 @@
|
||||
//! Copy as Markdown and paste as plain text, as Typora's Edit menu.
|
||||
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
use ely_office::prelude::*;
|
||||
use ely_ui::{commands, i18n::text};
|
||||
use gpui::{App, ClipboardItem, Context, InteractiveElement as _, KeyBinding, actions};
|
||||
|
||||
use crate::desk::Desk;
|
||||
|
||||
actions!(mark, [CopyMarkdown, PastePlain]);
|
||||
|
||||
pub fn bind(cx: &mut App) {
|
||||
let at = Some(commands::CONTEXT);
|
||||
cx.bind_keys([
|
||||
KeyBinding::new("secondary-shift-c", CopyMarkdown, at),
|
||||
KeyBinding::new("secondary-shift-v", PastePlain, at),
|
||||
]);
|
||||
}
|
||||
|
||||
impl Desk {
|
||||
/// The selected Markdown, or the whole text, as written.
|
||||
fn copy_markdown(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(view) = self.active_view() else {
|
||||
return self.no_document(cx);
|
||||
};
|
||||
let document = view.read(cx).document().read(cx);
|
||||
let selected = document.selected(cx);
|
||||
let markdown = match selected.is_empty() {
|
||||
true => document.text(cx),
|
||||
false => selected,
|
||||
};
|
||||
log::info!("mark: {} bytes copied as Markdown", markdown.len());
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(markdown));
|
||||
}
|
||||
|
||||
/// The clipboard's text at the caret, pictures left out.
|
||||
fn paste_plain(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(view) = self.active_view() else {
|
||||
return self.no_document(cx);
|
||||
};
|
||||
let Some(pasted) = cx.read_from_clipboard().and_then(|item| item.text()) else {
|
||||
let said = text(cx, "mark.paste.none", &[]);
|
||||
return self.toast(said, Severity::Info, cx);
|
||||
};
|
||||
let document = view.read(cx).document().clone();
|
||||
if !document.update(cx, |document, cx| document.insert(&pasted, cx)) {
|
||||
let said = text(cx, "mark.preview.read_only", &[]);
|
||||
self.toast(said, Severity::Info, cx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clip_actions(root: gpui::Div, cx: &mut Context<Self>) -> gpui::Div {
|
||||
root.on_action(cx.listener(|desk, _: &CopyMarkdown, _, cx| desk.copy_markdown(cx)))
|
||||
.on_action(cx.listener(|desk, _: &PastePlain, _, cx| desk.paste_plain(cx)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user