From 15931fce1ea8103b5eece327583f60bb9fb854a4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 6 Nov 2015 15:40:52 -0500 Subject: [PATCH] FIX: Allow us to insert things between words. --- .../javascripts/discourse/components/d-editor.js.es6 | 4 ---- test/javascripts/components/d-editor-test.js.es6 | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 14c83b14081..71fcb6c5710 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -279,10 +279,6 @@ export default Ember.Component.extend({ let start = textarea.selectionStart; let end = textarea.selectionEnd; - if (start === end) { - start = end = textarea.value.length; - } - const value = textarea.value.substring(start, end); const pre = textarea.value.slice(0, start); const post = textarea.value.slice(end); diff --git a/test/javascripts/components/d-editor-test.js.es6 b/test/javascripts/components/d-editor-test.js.es6 index 08f3568fdbe..8891f9fb55f 100644 --- a/test/javascripts/components/d-editor-test.js.es6 +++ b/test/javascripts/components/d-editor-test.js.es6 @@ -411,6 +411,18 @@ testCase(`heading button with no selection`, function(assert, textarea) { }); }); +testCase(`rule between things`, function(assert, textarea) { + textarea.selectionStart = 5; + textarea.selectionEnd = 5; + + click(`button.rule`); + andThen(() => { + assert.equal(this.get('value'), `hello\n\n----------\n world.`); + assert.equal(textarea.selectionStart, 18); + assert.equal(textarea.selectionEnd, 18); + }); +}); + testCase(`rule with no selection`, function(assert, textarea) { click(`button.rule`); andThen(() => {