Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -370,12 +370,7 @@ |
371 | 371 | context.oldHTML = newHTML; |
372 | 372 | event.data.scope = 'realchange'; |
373 | 373 | } |
374 | | - // Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s |
375 | | - switch ( event.which ) { |
376 | | - case 8: // backspace |
377 | | - // do something here... |
378 | | - break; |
379 | | - } |
| 374 | + |
380 | 375 | return true; |
381 | 376 | }, |
382 | 377 | 'delayedChange': function( event ) { |
— | — | @@ -385,6 +380,17 @@ |
386 | 381 | context.oldDelayedHTML = newHTML; |
387 | 382 | event.data.scope = 'realchange'; |
388 | 383 | } |
| 384 | + |
| 385 | + //surround by <p> if it does not already have it |
| 386 | + var t = context.fn.getOffset(); |
| 387 | + if ( t.node.parentNode.nodeName.toLowerCase() == 'body' ) { |
| 388 | + var cursorPos = context.fn.getCaretPosition()[0]; |
| 389 | + $( t.node ).wrap( "<p></p>" ); |
| 390 | + context.fn.refreshOffsets(); |
| 391 | + context.fn.setSelection( { start: cursorPos, end: cursorPos } ); |
| 392 | + } |
| 393 | + |
| 394 | + |
389 | 395 | context.fn.updateHistory( event.data.scope == 'realchange' ); |
390 | 396 | return true; |
391 | 397 | }, |
— | — | @@ -437,7 +443,7 @@ |
438 | 444 | } |
439 | 445 | t = t.next(); |
440 | 446 | } |
441 | | - // MS Word + webkit |
| 447 | + // MS Word + webkit |
442 | 448 | context.$content.find( 'p:not(.wikiEditor) p:not(.wikiEditor)' ) |
443 | 449 | .each( function(){ |
444 | 450 | var outerParent = $(this).parent(); |
— | — | @@ -1564,10 +1570,10 @@ |
1565 | 1571 | end = e ? e.offset : null; |
1566 | 1572 | // Don't try to set the selection past the end of a node, causes errors |
1567 | 1573 | // Just put the selection at the end of the node in this case |
1568 | | - if ( sc.nodeName == '#text' && start >= sc.nodeValue.length ) { |
| 1574 | + if ( sc.nodeName == '#text' && start > sc.nodeValue.length ) { |
1569 | 1575 | start = sc.nodeValue.length - 1; |
1570 | 1576 | } |
1571 | | - if ( ec.nodeName == '#text' && end >= ec.nodeValue.length ) { |
| 1577 | + if ( ec.nodeName == '#text' && end > ec.nodeValue.length ) { |
1572 | 1578 | end = ec.nodeValue.length - 1; |
1573 | 1579 | } |
1574 | 1580 | } |