add Cmd+T insert table, wire table/preview shortcuts through performKeyEquivalent

This commit is contained in:
jess 2026-04-07 18:37:44 -07:00
parent 88e134c01c
commit 558b41171e
3 changed files with 44 additions and 6 deletions

View File

@ -159,7 +159,7 @@ class IcedViewportView: NSView {
if cmd && !shift { if cmd && !shift {
switch chars { switch chars {
case "a", "c", "v", "x", "z", "p", case "a", "c", "v", "x", "z", "p", "t",
"=", "+", "-", "0": "=", "+", "-", "0":
keyDown(with: event) keyDown(with: event)
return true return true

View File

@ -1,3 +1,5 @@
use std::sync::Arc;
use iced_wgpu::core::keyboard; use iced_wgpu::core::keyboard;
use iced_wgpu::core::keyboard::key; use iced_wgpu::core::keyboard::key;
use iced_wgpu::core::text::{Highlight, Wrapping}; use iced_wgpu::core::text::{Highlight, Wrapping};
@ -13,6 +15,7 @@ pub enum Message {
EditorAction(text_editor::Action), EditorAction(text_editor::Action),
TogglePreview, TogglePreview,
MarkdownLink(markdown::Uri), MarkdownLink(markdown::Uri),
InsertTable,
ZoomIn, ZoomIn,
ZoomOut, ZoomOut,
ZoomReset, ZoomReset,
@ -42,11 +45,35 @@ fn md_style() -> markdown::Style {
impl EditorState { impl EditorState {
pub fn new() -> Self { pub fn new() -> Self {
let sample = concat!(
"# Heading 1\n\n",
"## Heading 2\n\n",
"### Heading 3\n\n",
"Regular text with **bold** and *italic* and `inline code`.\n\n",
"- Bullet one\n",
"- Bullet two\n",
"- Bullet three\n\n",
"1. First\n",
"2. Second\n",
"3. Third\n\n",
"> This is a blockquote\n\n",
"```python\n",
"def hello():\n",
" print(\"Hello world\")\n",
"```\n\n",
"| Name | Age | City |\n",
"|------|-----|------|\n",
"| Alice | 30 | NYC |\n",
"| Bob | 25 | LA |\n\n",
"---\n\n",
"[Link text](https://example.com)\n",
);
let parsed = markdown::parse(sample).collect();
Self { Self {
content: text_editor::Content::new(), content: text_editor::Content::with_text(sample),
font_size: 14.0, font_size: 14.0,
preview: false, preview: true,
parsed: Vec::new(), parsed,
} }
} }
@ -64,6 +91,13 @@ impl EditorState {
self.reparse(); self.reparse();
} }
} }
Message::InsertTable => {
let table = "| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| | | |\n| | | |\n";
self.content.perform(text_editor::Action::Edit(
text_editor::Edit::Paste(Arc::new(table.to_string())),
));
self.reparse();
}
Message::TogglePreview => { Message::TogglePreview => {
self.preview = !self.preview; self.preview = !self.preview;
if self.preview { if self.preview {

View File

@ -164,8 +164,12 @@ pub fn render(handle: &mut ViewportHandle) {
.. ..
}) = event }) = event
{ {
if c.as_str() == "p" && modifiers.logo() { if modifiers.logo() {
messages.push(Message::TogglePreview); match c.as_str() {
"p" => messages.push(Message::TogglePreview),
"t" => messages.push(Message::InsertTable),
_ => {}
}
} }
} }
} }