Skip to content

Commit 7f58a33

Browse files
committed
feat: add redo, undo commands.
1 parent eced987 commit 7f58a33

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/commands/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { quote } from './quote';
1010
import { link } from './link';
1111
import { todo } from './todo';
1212
import { image } from './image';
13+
import { redo } from './redo';
14+
import { undo } from './undo';
1315
import { fullscreen } from './fullscreen';
1416
import { preview } from './preview';
1517
import { IMarkdownEditor, ToolBarProps } from '../';
@@ -25,6 +27,8 @@ export type ICommand = {
2527
};
2628

2729
export const defaultCommands = {
30+
undo,
31+
redo,
2832
bold,
2933
italic,
3034
header,

src/commands/redo.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { redo as redoHandle } from '@codemirror/commands';
2+
import { ICommand } from './';
3+
4+
export const redo: ICommand = {
5+
name: 'redo',
6+
keyCommand: 'redo',
7+
button: { 'aria-label': 'redo text' },
8+
icon: (
9+
<svg viewBox="0 0 512 512" height="14" width="14">
10+
<path d="M58.79,439.13A16,16,0,0,1,48,424c0-73.1,14.68-131.56,43.65-173.77,35-51,90.21-78.46,164.35-81.87V88a16,16,0,0,1,27.05-11.57l176,168a16,16,0,0,1,0,23.14l-176,168A16,16,0,0,1,256,424V344.23c-45,1.36-79,8.65-106.07,22.64-29.25,15.12-50.46,37.71-73.32,67a16,16,0,0,1-17.82,5.28Z" />
11+
</svg>
12+
),
13+
execute: ({ state, view }) => {
14+
if (!state || !view) return;
15+
redoHandle(view);
16+
},
17+
};

src/commands/undo.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { undo as undoHandle } from '@codemirror/commands';
2+
import { ICommand } from './';
3+
4+
export const undo: ICommand = {
5+
name: 'undo',
6+
keyCommand: 'undo',
7+
button: { 'aria-label': 'undo text' },
8+
icon: (
9+
<svg viewBox="0 0 512 512" height="14" width="14">
10+
<path d="M448,440a16,16,0,0,1-12.61-6.15c-22.86-29.27-44.07-51.86-73.32-67C335,352.88,301,345.59,256,344.23V424A16,16,0,0,1,229,435.57l-176-168a16,16,0,0,1,0-23.14l176-168A16,16,0,0,1,256,88v80.36c74.14,3.41,129.38,30.91,164.35,81.87C449.32,292.44,464,350.9,464,424a16,16,0,0,1-16,16Z" />
11+
</svg>
12+
),
13+
execute: ({ state, view }) => {
14+
if (!state || !view) return;
15+
undoHandle(view);
16+
},
17+
};

0 commit comments

Comments
 (0)