@@ -864,17 +864,17 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
864
864
} else {
865
865
// if enter - insert new taDefaultWrap, if shift+enter insert <br/>
866
866
if ( _defaultVal !== '' && _defaultVal !== '<BR><BR>' && event . keyCode === _ENTER_KEYCODE && ! event . ctrlKey && ! event . metaKey && ! event . altKey ) {
867
+ var selection = taSelection . getSelectionElement ( ) ;
868
+ while ( ! selection . nodeName . match ( VALIDELEMENTS ) && selection !== element [ 0 ] ) {
869
+ selection = selection . parentNode ;
870
+ }
867
871
if ( ! event . shiftKey ) {
868
872
// new paragraph, br should be caught correctly
869
- var selection = taSelection . getSelectionElement ( ) ;
870
873
// shifted to nodeName here from tagName since it is more widely supported see: http://stackoverflow.com/questions/4878484/difference-between-tagname-and-nodename
871
- while ( ! selection . nodeName . match ( VALIDELEMENTS ) && selection !== element [ 0 ] ) {
872
- selection = selection . parentNode ;
873
- }
874
-
874
+ //console.log('Enter', selection.nodeName, attrs.taDefaultWrap, selection.innerHTML.trim());
875
875
if ( selection . tagName . toLowerCase ( ) !==
876
876
attrs . taDefaultWrap &&
877
- selection . tagName . toLowerCase ( ) !== 'li' &&
877
+ selection . nodeName . toLowerCase ( ) !== 'li' &&
878
878
( selection . innerHTML . trim ( ) === '' || selection . innerHTML . trim ( ) === '<br>' )
879
879
) {
880
880
// Chrome starts with a <div><br></div> after an EnterKey
@@ -883,6 +883,29 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
883
883
angular . element ( selection ) . replaceWith ( _new ) ;
884
884
taSelection . setSelectionToElementStart ( _new [ 0 ] ) ;
885
885
}
886
+ } else {
887
+ // shift + Enter
888
+ var tagName = selection . tagName . toLowerCase ( ) ;
889
+ //console.log('Shift+Enter', selection.tagName, attrs.taDefaultWrap, selection.innerHTML.trim());
890
+ // For an LI: We see: LI p ....<br><br>
891
+ // For a P: We see: P p ....<br><br>
892
+ // on Safari, the browser ignores the Shift+Enter and acts just as an Enter Key
893
+ // For an LI: We see: LI p <br>
894
+ // For a P: We see: P p <br>
895
+ if ( ( tagName === attrs . taDefaultWrap ||
896
+ tagName === 'li' ||
897
+ tagName === 'pre' ||
898
+ tagName === 'div' ) &&
899
+ ! / .+ < b r > < b r > / . test ( selection . innerHTML . trim ( ) ) ) {
900
+ var ps = selection . previousSibling ;
901
+ //console.log('wrong....', ps);
902
+ // we need to remove this selection and fix the previousSibling up...
903
+ if ( ps ) {
904
+ ps . innerHTML = ps . innerHTML + '<br><br>' ;
905
+ angular . element ( selection ) . remove ( ) ;
906
+ taSelection . setSelectionToElementEnd ( ps ) ;
907
+ }
908
+ }
886
909
}
887
910
}
888
911
var val = _compileHtml ( ) ;
0 commit comments