diff --git a/client/components/codeEditor/customKeyMaps.js b/client/components/codeEditor/customKeyMaps.js index 194f79167..717f30f4e 100644 --- a/client/components/codeEditor/customKeyMaps.js +++ b/client/components/codeEditor/customKeyMaps.js @@ -29,27 +29,25 @@ const indentLess = (view)=>{ }; const wrapSelection = (prefix, suffix) => (view) => { - const { from, to } = view.state.selection.main; - const selected = view.state.doc.sliceString(from, to); + const changes = []; - let text, selection; + for(const range of view.state.selection.ranges) { + const { from, to } = range; + const selected = view.state.doc.sliceString(from, to); - if(from === to) { - text = prefix + suffix; - selection = { anchor: from + prefix.length, head: from + prefix.length }; - } - else if(selected.startsWith(prefix) && selected.endsWith(suffix)) { - text = selected.slice(prefix.length, -suffix.length); - selection = { anchor: from, head: from + text.length }; - } - else { - text = `${prefix}${selected}${suffix}`; - selection = { anchor: from, head: from + text.length }; + let text; + + if(from === to) { text = prefix + suffix } + else if(selected.startsWith(prefix) && selected.endsWith(suffix)) { + text = selected.slice(prefix.length, -suffix.length); + } + else {text = `${prefix}${selected}${suffix}`} + + changes.push({ from, to, insert: text }); } view.dispatch({ - changes : { from, to, insert: text }, - selection + changes }); return true;