Skip to content

Commit d97842c

Browse files
SimeonCSimeonC
SimeonC
authored and
SimeonC
committed
fix(taExecCommand): Fix List conversion bug.
Fixes #399
1 parent f9d7e42 commit d97842c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

dist/textAngular.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/DOM.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
9999
if(_nodes[i].tagName.toLowerCase() === 'li') continue;
100100
else if(_nodes[i].tagName.toLowerCase() === 'ol' || _nodes[i].tagName.toLowerCase() === 'ul'){
101101
html += $n[0].innerHTML; // if it's a list, add all it's children
102+
}else if(_nodes[i].tagName.toLowerCase() === 'span' && (_nodes[i].childNodes[0].tagName.toLowerCase() === 'ol' || _nodes[i].childNodes[0].tagName.toLowerCase() === 'ul')){
103+
html += $n[0].childNodes[0].innerHTML; // if it's a list, add all it's children
102104
}else{
103105
html += '<' + taBrowserTag('li') + '>' + $n[0].innerHTML + '</' + taBrowserTag('li') + '>';
104106
}

src/textAngular.js

+2
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ angular.module('textAngular.DOM', ['textAngular.factories'])
382382
if(_nodes[i].tagName.toLowerCase() === 'li') continue;
383383
else if(_nodes[i].tagName.toLowerCase() === 'ol' || _nodes[i].tagName.toLowerCase() === 'ul'){
384384
html += $n[0].innerHTML; // if it's a list, add all it's children
385+
}else if(_nodes[i].tagName.toLowerCase() === 'span' && (_nodes[i].childNodes[0].tagName.toLowerCase() === 'ol' || _nodes[i].childNodes[0].tagName.toLowerCase() === 'ul')){
386+
html += $n[0].childNodes[0].innerHTML; // if it's a list, add all it's children
385387
}else{
386388
html += '<' + taBrowserTag('li') + '>' + $n[0].innerHTML + '</' + taBrowserTag('li') + '>';
387389
}

test/taExecCommand/taExecCommand.lists.spec.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('taExecCommand', function(){
181181
}));
182182
});
183183
});
184-
describe('list to other', function(){
184+
describe('list to other/list', function(){
185185
var element;
186186
describe('li selected', function(){
187187
it('from ol', inject(function(taSelection, taExecCommand){
@@ -198,6 +198,34 @@ describe('taExecCommand', function(){
198198
}));
199199
});
200200
describe('list selected', function(){
201+
describe('edge mixed case', function(){
202+
it('to ol', inject(function(taSelection, taExecCommand){
203+
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><span><ul><li>To the List!</li></ul></span></div>');
204+
taSelection.element = element[0];
205+
taExecCommand()('insertorderedlist', false, null);
206+
expect(element.html()).toBe('<ol><li>To the List!</li><li>To the List!</li></ol>');
207+
}));
208+
it('to ul', inject(function(taSelection, taExecCommand){
209+
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><span><ul><li>To the List!</li></ul></span></div>');
210+
taSelection.element = element[0];
211+
taExecCommand()('insertunorderedlist', false, null);
212+
expect(element.html()).toBe('<ul><li>To the List!</li><li>To the List!</li></ul>');
213+
}));
214+
});
215+
describe('mixed as child of ta-bind', function(){
216+
it('to ol', inject(function(taSelection, taExecCommand){
217+
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><ul><li>To the List!</li></ul></div>');
218+
taSelection.element = element[0];
219+
taExecCommand()('insertorderedlist', false, null);
220+
expect(element.html()).toBe('<ol><li>To the List!</li><li>To the List!</li></ol>');
221+
}));
222+
it('to ul', inject(function(taSelection, taExecCommand){
223+
element = angular.element('<div class="ta-bind"><ol><li>To the List!</li></ol><ul><li>To the List!</li></ul></div>');
224+
taSelection.element = element[0];
225+
taExecCommand()('insertunorderedlist', false, null);
226+
expect(element.html()).toBe('<ul><li>To the List!</li><li>To the List!</li></ul>');
227+
}));
228+
});
201229
describe('from ol', function(){
202230
describe('as child of ta-bind', function(){
203231
it('to default', inject(function(taSelection, taExecCommand){

0 commit comments

Comments
 (0)