Skip to content

Commit

Permalink
Merge pull request #375 from bustlelabs/fix-section-text-expansion
Browse files Browse the repository at this point in the history
[bugfix] Ensure cursor is in li after "* " expands to li
  • Loading branch information
bantic committed Apr 26, 2016
2 parents f8582fc + be898fb commit 2b035e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/editor/text-input-handlers.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,6 +17,7 @@ function replaceWithListSection(editor, listTagName) {
let listSection = builder.createListSection(listTagName, [item]);

postEditor.replaceSection(section, listSection);
postEditor.setRange(new Range(listSection.headPosition()));
});
}

Expand Down
7 changes: 7 additions & 0 deletions tests/acceptance/editor-input-handlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit 2b035e6

Please sign in to comment.