From c65244d1f5fa9164cbf62e2328e9a46d614ce465 Mon Sep 17 00:00:00 2001 From: Stephen Lavelle Date: Wed, 9 Sep 2015 11:45:07 +0100 Subject: [PATCH] [closebrackets addon] When wrapping selection, create new selection without brackets Right now if you have a selection, and you enter a bracket/quote, surrounds it with quotation marks, and selects the entire quote. This change should change the behaviour to selecting the interior of the quote instead. The motivating example for me was autocomplete, where after autocompleting a function the arguments are selected, so if you want to insert a string literal right now you have to delete the selection before you can enter the quotes. With the proposed fix, it'll be rather more fluid. --- addon/edit/closebrackets.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/addon/edit/closebrackets.js b/addon/edit/closebrackets.js index 7030268b03..bd183c32cc 100644 --- a/addon/edit/closebrackets.js +++ b/addon/edit/closebrackets.js @@ -90,6 +90,16 @@ }); } + function contractSelection(sel){ + if (sel.anchor.linesel.head.line || (sel.anchor.line===sel.head.line&&sel.anchor.ch>sel.head.ch)){ + sel.head.ch++; + sel.anchor.ch--; + } + } function handleChar(cm, ch) { var conf = getConfig(cm); if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass; @@ -145,6 +155,11 @@ for (var i = 0; i < sels.length; i++) sels[i] = left + sels[i] + right; cm.replaceSelections(sels, "around"); + var selections = cm.listSelections(); + for (var i=0;i