Skip to content

Commit 63480a6

Browse files
SimeonCSimeonC
SimeonC
authored and
SimeonC
committed
fix(taExecCommand): Fixes blockquote issue.
Fixes #377
1 parent 717c291 commit 63480a6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/textAngular.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,10 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
900900
if(tagName === 'li') $target = $selected.parent();
901901
else $target = $selected;
902902
// find the first blockElement
903-
while(!$target[0].tagName.match(BLOCKELEMENTS)){
903+
while(!$target[0].tagName || !$target[0].tagName.match(BLOCKELEMENTS) && !$target.parent().attr('contenteditable')){
904904
$target = $target.parent();
905-
tagName = $target[0].tagName.toLowerCase();
905+
/* istanbul ignore next */
906+
tagName = ($target[0].tagName || '').toLowerCase();
906907
}
907908
if(tagName === optionsTagName){
908909
// $target is wrap element
@@ -964,9 +965,10 @@ See README.md or https://github.com/fraywing/textAngular/wiki for requirements a
964965
$target = angular.element(options);
965966
$target[0].innerHTML = html;
966967
_nodes[0].parentNode.insertBefore($target[0],_nodes[0]);
967-
angular.forEach(_nodes, function(node){
968-
node.parentNode.removeChild(node);
969-
});
968+
for(i = _nodes.length - 1; i >= 0; i--){
969+
/* istanbul ignore else: */
970+
if(_nodes[i].parentNode) _nodes[i].parentNode.removeChild(_nodes[i]);
971+
}
970972
}
971973
else {
972974
// regular block elements replace other block elements

test/taExecCommand.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ describe('taExecCommand', function(){
175175
$element.remove();
176176
}));
177177
it('selection with multiple nodes', inject(function($document, taExecCommand, taSelection){
178-
$element = angular.element('<div class="ta-bind"><p>Some <b>test</b> content</p><p>Some <b>test</b> content</p></div>');
178+
$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>');
179179
$document.find('body').append($element);
180180
taSelection.element = $element[0];
181181
taExecCommand()('formatBlock', false, '<BLOCKQUOTE>');
182-
expect($element.html()).toBe('<blockquote><p>Some <b>test</b> content</p><p>Some <b>test</b> content</p></blockquote>');
182+
expect($element.html()).toBe('<blockquote><p>Some <b>test</b> content</p><p><br></p><p>Some <b>test</b> content</p></blockquote>');
183183
$element.remove();
184184
}));
185185
});

0 commit comments

Comments
 (0)