add Cmd+T insert table, wire table/preview shortcuts through performKeyEquivalent
This commit is contained in:
parent
88e134c01c
commit
558b41171e
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue