Skip to content

Commit

Permalink
fix(taExecCommand): Attempt to wrap unwrapped content in list breaks.
Browse files Browse the repository at this point in the history
Fix #362
  • Loading branch information
SimeonC authored and SimeonC committed Oct 23, 2014
1 parent 5ff572f commit 7b873df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/textAngular.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,12 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
}else if(tagName.match(BLOCKELEMENTS)){
// if we get here then all the contents of the ta-bind are selected
_nodes = taSelection.getOnlySelectedElements();
if(_nodes.length === 1 && (_nodes[0].tagName.toLowerCase() === 'ol' || _nodes[0].tagName.toLowerCase() === 'ul')){
if(_nodes.length === 0){
// here is if there is only text in ta-bind ie <div ta-bind>test content</div>
$target = angular.element('<' + selfTag + '><li>' + selectedElement.innerHTML + '</li></' + selfTag + '>');
$selected.html('');
$selected.append($target);
}else if(_nodes.length === 1 && (_nodes[0].tagName.toLowerCase() === 'ol' || _nodes[0].tagName.toLowerCase() === 'ul')){
if(_nodes[0].tagName.toLowerCase() === selfTag){
// remove
return listToDefault(angular.element(_nodes[0]), taDefaultWrap);
Expand All @@ -884,13 +889,8 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
}
}
$target = angular.element('<' + selfTag + '>' + html + '</' + selfTag + '>');
if($nodes.length){
$nodes.pop().replaceWith($target);
angular.forEach($nodes, function($node){ $node.remove(); });
}else{
// selection was empty, insert html (cursor moved automatically)
return taSelection.insertHtml('<' + selfTag + '>' + html + '</' + selfTag + '>');
}
$nodes.pop().replaceWith($target);
angular.forEach($nodes, function($node){ $node.remove(); });
}
taSelection.setSelectionToElementEnd($target[0]);
return;
Expand Down
20 changes: 18 additions & 2 deletions test/taExecCommand.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,28 @@ describe('taExecCommand', function(){
}));
it('to ol', inject(function(taSelection, taExecCommand){
taExecCommand()('insertorderedlist', false, null);
expect(insertedHtml).toBe('<ol></ol>');
expect(insertedHtml).toBe('');
}));

it('to ul', inject(function(taSelection, taExecCommand){
taExecCommand()('insertunorderedlist', false, null);
expect(insertedHtml).toBe('<ul></ul>');
expect(insertedHtml).toBe('');
}));
});
describe('text-only ta-bind', function(){
beforeEach(inject(function(taSelection){
element = angular.element('<div class="ta-bind">testsomecontent</div>');
taSelection.element = element[0];
taSelection.getOnlySelectedElements = function(){ return []; };
}));
it('to ol', inject(function(taSelection, taExecCommand){
taExecCommand()('insertorderedlist', false, null);
expect(element.html()).toBe('<ol><li>testsomecontent</li></ol>');
}));

it('to ul', inject(function(taSelection, taExecCommand){
taExecCommand()('insertunorderedlist', false, null);
expect(element.html()).toBe('<ul><li>testsomecontent</li></ul>');
}));
});
describe('single element selected', function(){
Expand Down

0 comments on commit 7b873df

Please sign in to comment.