Changeset 1178
- Timestamp:
- 04/09/09 18:46:46 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Ticket1226/paraHandlerBest.js
r1176 r1178 858 858 * Test suite for this, because it's really tough to get right. 859 859 */ 860 EnterParagraphs.RunTests = function(xinha )860 EnterParagraphs.RunTests = function(xinha, debug) 861 861 { 862 function test(before, cursorBefore, after, cursorAfter) { 863 xinha.setHTML(before); 862 function test(message, before, cursorBefore, after, cursorAfter) { 863 console.group('Test: ', message, null, before); 864 if (before !== null) { 865 xinha.setHTML(before); 866 } 864 867 // Do something 865 868 var cAnchor, cOffset; 866 869 867 870 var mockEvent = { 868 preventDefault: function() { console.log("Preventing default.");},869 stopPropagation: function() { console.log("Stopping propagation.");},871 preventDefault: function() {if (debug) console.log("Preventing default.");}, 872 stopPropagation: function() {if (debug) console.log("Stopping propagation.");}, 870 873 } 871 874 function setCursor(commands) { … … 876 879 if ('id' == command[0]) { 877 880 cAnchor = xinha._doc.getElementById(command[1]); 881 } else if ('tag' == command[0]) { 882 cAnchor = xinha._doc.getElementsByTagName(command[1])[0]; 878 883 } else if ('child' == command[0]) { 879 884 cAnchor = cAnchor.childNodes[command[1]]; … … 887 892 } 888 893 } else if ('offset' == command[0]) { 889 cOffset = command[1]; 894 if (command[1] == 'length') { 895 if (TEXT_NODE == cAnchor.nodeType) { 896 cOffset = cAnchor.nodeValue.length; 897 } else { 898 cOffset = cAnchor.childNodes.length; 899 } 900 } else if (command[1] < 0) { 901 if (TEXT_NODE == cAnchor.nodeType) { 902 cOffset = cAnchor.nodeValue.length + command[1]; 903 } else { 904 cOffset = cAnchor.childNodes.length + command[1]; 905 } 906 } else { 907 cOffset = command[1]; 908 } 890 909 } 891 910 } … … 902 921 selection.addRange(range); 903 922 904 return;905 923 // Breakline 906 924 xinha.plugins['EnterParagraphs'].instance.breakLine(mockEvent, xinha._doc); … … 917 935 result = xinha.getInnerHTML(); 918 936 if (result == after) { 919 console.info(' Was', before, 'Got', after)937 console.info('Success!') 920 938 } else { 921 console.error('Was', before, 'Expected', after, 'Got', result) 922 } 939 console.error('Was', null, before, null, 'Expected', null, after, null, 'Got', null, result, null) 940 } 941 console.groupEnd(); 923 942 } 924 943 contentBackup = xinha.getInnerHTML(); 925 944 console.group('Running tests:'); 926 test('<h1 id="before">hi</h1>', [['id', 'before'], ['child', 0], ['offset', 2]], '<h1 id="before">hi</h1><h1></h1>', [['id', 'before'], ['next', 1], ['offset', 2]]); 945 /* 946 The initial content on browser load seems to be: 947 <body><br />\n</body> 948 That's a break tag and a whitespace text node containing a newline character. 949 */ 950 test('Initial Xinha Content', 951 null, [], 952 '<p> </p><p><br> </p>\n', [['child', 1]]); // Mozilla kicks off a trailing newline. Do I care about this? 953 test('Initial Xinha Content: Recreated', 954 '<br>\n', [], 955 '<p> </p><p><br> </p>\n', [['child', 1]]); // Mozilla kicks off a trailing newline. Do I care about this? 956 test('Empty Body', 957 '', [], 958 '<p> </p><p></p>', [['child', 1], ['offset', 0]]); 959 test('Text node in body', 960 'Hi', [], 961 '<p> </p><p>Hi</p>', [['child', 1], ['offset', 0]]); 962 test('Split h1', 963 '<h1 id="before">hi</h1>', [['id', 'before'], ['child', 0], ['offset', 2]], 964 '<h1 id="before">hi</h1><h1></h1>', [['id', 'before'], ['next', 1], ['offset', 2]]); 927 965 console.groupEnd(); 928 return;929 966 xinha.setHTML(contentBackup); 930 967 // EnterParagraphs.RunTests(xinha_editors['myTextArea']) … … 1476 1513 else 1477 1514 { 1478 var newCursor = splitTree(embedNode, treeRoot, cursorOffset, doc); 1515 var parentOffset = this.indexInParent(treeRoot); 1516 if (null === parentOffset) 1517 { 1518 // We can't do anything with this cursor, so return. 1519 return; 1520 } 1521 var newCursor = splitTree(embedNode, treeRoot.parentNode, parentOffset, doc); 1479 1522 } 1480 1523 }
Note: See TracChangeset
for help on using the changeset viewer.