From be898fbe623ae96da3ac9deeaf1f5fe87670ae17 Mon Sep 17 00:00:00 2001 From: Cory Forsyth Date: Tue, 26 Apr 2016 15:20:16 -0400 Subject: [PATCH] [bugfix] Ensure cursor is in li after "* " expands to li --- src/js/editor/text-input-handlers.js | 3 +++ tests/acceptance/editor-input-handlers-test.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/js/editor/text-input-handlers.js b/src/js/editor/text-input-handlers.js index a453add2f..52438fc24 100644 --- a/src/js/editor/text-input-handlers.js +++ b/src/js/editor/text-input-handlers.js @@ -1,3 +1,5 @@ +import Range from 'mobiledoc-kit/utils/cursor/range'; + function replaceWithListSection(editor, listTagName) { let { range: { head, head: { section } } } = editor; // Skip if cursor is not at end of section @@ -15,6 +17,7 @@ function replaceWithListSection(editor, listTagName) { let listSection = builder.createListSection(listTagName, [item]); postEditor.replaceSection(section, listSection); + postEditor.setRange(new Range(listSection.headPosition())); }); } diff --git a/tests/acceptance/editor-input-handlers-test.js b/tests/acceptance/editor-input-handlers-test.js index 552fff2b4..1be2ea2da 100644 --- a/tests/acceptance/editor-input-handlers-test.js +++ b/tests/acceptance/editor-input-handlers-test.js @@ -70,6 +70,13 @@ test('typing "* " converts to ul > li', (assert) => { assert.hasNoElement('#editor p', 'p is gone'); assert.hasElement('#editor ul > li', 'p -> "ul > li"'); + let li = $('#editor ul > li')[0]; + assert.ok(li, 'has li for cursor position'); + + let selection = window.getSelection(); + assert.equal(selection.anchorNode, li, 'selection anchorNode is li'); + assert.equal(selection.focusNode, li, 'selection focusNode is li'); + Helpers.dom.insertText(editor, 'X'); assert.hasElement('#editor ul > li:contains(X)', 'text is inserted correctly'); });