Skip to content

Commit 8e63a30

Browse files
committed
fix: Fix codeBlock command issue. (#193)
1 parent 323860c commit 8e63a30

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/commands/code.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ export const codeBlock: ICommand = {
5555
),
5656
execute: ({ state, view }) => {
5757
if (!state || !view) return;
58-
view.dispatch(
59-
view.state.changeByRange((range) => ({
60-
changes: [
61-
{ from: range.from, insert: '```js\n' },
62-
{ from: range.to, insert: '\n```' },
63-
],
64-
range: EditorSelection.range(range.from + 5, range.to + 3),
65-
})),
66-
);
58+
const main = view.state.selection.main;
59+
const txt = view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to);
60+
view.dispatch({
61+
changes: {
62+
from: main.from,
63+
to: main.to,
64+
insert: `\`\`\`js\n${txt}\n\`\`\``,
65+
},
66+
selection: EditorSelection.range(main.from + 3, main.from + 5),
67+
});
6768
},
6869
};

0 commit comments

Comments
 (0)