File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff 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} ;
You can’t perform that action at this time.
0 commit comments