Skip to content

Commit

Permalink
fix(taBind): Issue when unwrapped text was entered
Browse files Browse the repository at this point in the history
Fixes #484
  • Loading branch information
SimeonC authored and SimeonC committed Jan 19, 2015
1 parent 23cb9f1 commit 51f3728
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 91 deletions.
6 changes: 6 additions & 0 deletions lib/taBind.js
Expand Up @@ -427,6 +427,12 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
if(_defaultVal !== '' && val.trim() === ''){
_setInnerHTML(_defaultVal);
taSelection.setSelectionToElementStart(element.children()[0]);
}else if(val.substring(0, 1) !== '<' && attrs.taDefaultWrap !== ''){
var _savedSelection = $window.rangy.saveSelection();
val = _compileHtml();
val = "<" + attrs.taDefaultWrap + ">" + val + "</" + attrs.taDefaultWrap + ">";
_setInnerHTML(val);
$window.rangy.restoreSelection(_savedSelection);
}
var triggerUndo = _lastKey !== event.keyCode && UNDO_TRIGGER_KEYS.test(event.keyCode);
_setViewValue(val, triggerUndo);
Expand Down
89 changes: 39 additions & 50 deletions test/taBind/taBind.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions test/textAngular.spec.js
Expand Up @@ -547,47 +547,6 @@ describe('textAngular', function(){
});
});
});

describe('484', function(){
var displayElements;
beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
$rootScope = _$rootScope_;
$rootScope.html = undefined;
element = _$compile_('<text-angular name="test" ng-model="html"></text-angular>')($rootScope);
$rootScope.$digest();
displayElements = textAngularManager.retrieveEditor('test').scope.displayElements;
}));
it('should initialize correctly', function() {
expect(displayElements.html.val()).toBe('');
expect($rootScope.html).toBe(undefined);
});
it('it should wrap chars into a <p>-tag', function() {
displayElements.text.html('f'); //maybe there is a <p></p>
displayElements.text.triggerHandler('keyup', {which: 70});
$rootScope.$digest();
expect(displayElements.html.val()).toBe('<p>f</p>');
expect($rootScope.html).toBe('<p>f</p>'); //but apparently it is just 'f'
});
it('it should be able to add a <br/> after entering text', function() {
displayElements.text.html('f');
displayElements.text.triggerHandler('keyup', {which: 70});
displayElements.text.html('f<br/>');
displayElements.text.triggerHandler('keyup', {which: 13});
$rootScope.$digest();
expect(displayElements.html.val()).toBe('<p>f</p><br/>');
expect($rootScope.html).toBe('<p>f</p><br/>');
});
it('it correctly adds a <br/> when text is wrapped in <p>', function() {
displayElements.text.html('<p>f</p>');
displayElements.text.triggerHandler('keyup', {which: 70});
displayElements.text.html('<p>f</p><br/>');
displayElements.text.triggerHandler('keyup', {which: 13});
$rootScope.$digest();
expect(displayElements.html.val()).toBe('<p>f</p><br/>');
expect($rootScope.html).toBe('<p>f</p><br/>');
});
});

describe('Basic Initiation with ng-model and originalContents', function(){
var displayElements;
beforeEach(inject(function (_$compile_, _$rootScope_, textAngularManager) {
Expand Down

0 comments on commit 51f3728

Please sign in to comment.