diff --git a/src/IcedViewportView.swift b/src/IcedViewportView.swift index 007dda9..47bb010 100644 --- a/src/IcedViewportView.swift +++ b/src/IcedViewportView.swift @@ -159,7 +159,7 @@ class IcedViewportView: NSView { if cmd && !shift { switch chars { - case "a", "c", "v", "x", "z", "p", + case "a", "c", "v", "x", "z", "p", "t", "=", "+", "-", "0": keyDown(with: event) return true diff --git a/viewport/src/editor.rs b/viewport/src/editor.rs index 125b6ca..51d4f76 100644 --- a/viewport/src/editor.rs +++ b/viewport/src/editor.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use iced_wgpu::core::keyboard; use iced_wgpu::core::keyboard::key; use iced_wgpu::core::text::{Highlight, Wrapping}; @@ -13,6 +15,7 @@ pub enum Message { EditorAction(text_editor::Action), TogglePreview, MarkdownLink(markdown::Uri), + InsertTable, ZoomIn, ZoomOut, ZoomReset, @@ -42,11 +45,35 @@ fn md_style() -> markdown::Style { impl EditorState { 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 { - content: text_editor::Content::new(), + content: text_editor::Content::with_text(sample), font_size: 14.0, - preview: false, - parsed: Vec::new(), + preview: true, + parsed, } } @@ -64,6 +91,13 @@ impl EditorState { 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 => { self.preview = !self.preview; if self.preview { diff --git a/viewport/src/handle.rs b/viewport/src/handle.rs index d6bffaf..45a70d0 100644 --- a/viewport/src/handle.rs +++ b/viewport/src/handle.rs @@ -164,8 +164,12 @@ pub fn render(handle: &mut ViewportHandle) { .. }) = event { - if c.as_str() == "p" && modifiers.logo() { - messages.push(Message::TogglePreview); + if modifiers.logo() { + match c.as_str() { + "p" => messages.push(Message::TogglePreview), + "t" => messages.push(Message::InsertTable), + _ => {} + } } } }