Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Ensure cursor is in li after "* " expands to li #375

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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