From ff28fdd1899faffcba76dc55e85cf310b195d3b5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 6 May 2012 14:53:33 +0900 Subject: [PATCH] when wrap called with empty selection, postion caret in middle --- aqt/editor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aqt/editor.py b/aqt/editor.py index ee4916709..87076634f 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -48,7 +48,6 @@ body { margin: 5px; } var currentField = null; var changeTimer = null; var insertHTMLOK = %s; -var savedSel = null; var dropTarget = null; String.prototype.format = function() { @@ -185,6 +184,14 @@ function wrap(front, back) { r.insertNode(document.createTextNode(new_)); saveField('key'); } + if (!span.innerHTML) { + // run with an empty selection; move cursor back past postfix + r = s.getRangeAt(0); + r.setStart(r.startContainer, r.startOffset - back.length); + r.collapse(true); + s.removeAllRanges(); + s.addRange(r); + } }; function setFields(fields, focusTo) {