fix(composer): list creation edge case fixes and tests

Fixes #1064
This commit is contained in:
Evan Morikawa 2016-01-22 10:33:39 -08:00
parent 948202af2d
commit ede5d49280
2 changed files with 20 additions and 2 deletions

View file

@ -81,6 +81,19 @@ describe('Contenteditable Integration Spec', function() {
}).then(done).catch(done.fail);
});
it("Doesn't create unordered lists with dash when it's not at the start of the composer", (done) => {
this.ce.test({
keys: ['asdf', 'Space', 'Back space', '-', 'Space'],
expectedHTML: `<spelling class="misspelled">asdf</spelling>-&nbsp;`,
expectedSelectionResolver: (dom) => {
return {
node: dom.childNodes[1],
offset: 2,
};
},
}).then(done).catch(done.fail);
});
it('Undoes unordered list creation with backspace', (done) => {
this.ce.test({
keys: ['-', 'Space', 'Back space'],
@ -192,6 +205,7 @@ describe('Contenteditable Integration Spec', function() {
expectedSelectionResolver: (dom) => {
return {
node: dom.querySelectorAll('li')[0].childNodes[0],
offset: 1
};
},
}).then(done).catch(done.fail);
@ -204,6 +218,7 @@ describe('Contenteditable Integration Spec', function() {
expectedSelectionResolver: (dom) => {
return {
node: dom.querySelectorAll('li')[0].childNodes[0],
offset: 1
};
},
}).then(done).catch(done.fail);

View file

@ -40,8 +40,11 @@ class ListManager extends ContenteditableExtension
return false unless selection?.anchorNode
return false if not selection.isCollapsed
sibling = selection.anchorNode.previousElementSibling
if not sibling or DOMUtils.looksLikeBlockElement(sibling)
text = selection.anchorNode.textContent
return @numberRegex().test(text) or @bulletRegex().test(text)
else return false
@createList: (editor) ->
text = editor.currentSelection().anchorNode?.textContent