Skip to content

Commit

Permalink
fix(taExecCommand): Fixes blockquote issue.
Browse files Browse the repository at this point in the history
Fixes #377
  • Loading branch information
SimeonC authored and SimeonC committed Nov 4, 2014
1 parent 717c291 commit 63480a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/textAngular.js
Expand Up @@ -900,9 +900,10 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
if(tagName === 'li') $target = $selected.parent();
else $target = $selected;
// find the first blockElement
while(!$target[0].tagName.match(BLOCKELEMENTS)){
while(!$target[0].tagName || !$target[0].tagName.match(BLOCKELEMENTS) && !$target.parent().attr('contenteditable')){
$target = $target.parent();
tagName = $target[0].tagName.toLowerCase();
/* istanbul ignore next */
tagName = ($target[0].tagName || '').toLowerCase();
}
if(tagName === optionsTagName){
// $target is wrap element
Expand Down Expand Up @@ -964,9 +965,10 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
$target = angular.element(options);
$target[0].innerHTML = html;
_nodes[0].parentNode.insertBefore($target[0],_nodes[0]);
angular.forEach(_nodes, function(node){
node.parentNode.removeChild(node);
});
for(i = _nodes.length - 1; i >= 0; i--){
/* istanbul ignore else: */
if(_nodes[i].parentNode) _nodes[i].parentNode.removeChild(_nodes[i]);
}
}
else {
// regular block elements replace other block elements
Expand Down
4 changes: 2 additions & 2 deletions test/taExecCommand.spec.js
Expand Up @@ -175,11 +175,11 @@ describe('taExecCommand', function(){
$element.remove();
}));
it('selection with multiple nodes', inject(function($document, taExecCommand, taSelection){
$element = angular.element('<div class="ta-bind"><p>Some <b>test</b> content</p><p>Some <b>test</b> content</p></div>');
$element = angular.element('<div class="ta-bind"><p>Some <b>test</b> content</p><p><br/></p><p>Some <b>test</b> content</p></div>');
$document.find('body').append($element);
taSelection.element = $element[0];
taExecCommand()('formatBlock', false, '<BLOCKQUOTE>');
expect($element.html()).toBe('<blockquote><p>Some <b>test</b> content</p><p>Some <b>test</b> content</p></blockquote>');
expect($element.html()).toBe('<blockquote><p>Some <b>test</b> content</p><p><br></p><p>Some <b>test</b> content</p></blockquote>');
$element.remove();
}));
});
Expand Down

0 comments on commit 63480a6

Please sign in to comment.