Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -379,18 +379,17 @@ |
380 | 380 | if ( context.oldDelayedHTML != newHTML ) { |
381 | 381 | context.oldDelayedHTML = newHTML; |
382 | 382 | event.data.scope = 'realchange'; |
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' ) { |
| 383 | + |
| 384 | + //surround by <p> if it does not already have it |
388 | 385 | var cursorPos = context.fn.getCaretPosition(); |
389 | | - $( t.node ).wrap( "<p></p>" ); |
390 | | - context.fn.purgeOffsets(); |
391 | | - context.fn.setSelection( { start: cursorPos[0], end: cursorPos[1] } ); |
392 | | - } |
393 | | - |
394 | | - |
| 386 | + var t = context.fn.getOffset(cursorPos[0]); |
| 387 | + if ( t.node.parentNode.nodeName.toLowerCase() == 'body' ) { |
| 388 | + $( t.node ).wrap( "<p></p>" ); |
| 389 | + context.fn.purgeOffsets(); |
| 390 | + context.fn.setSelection( { start: cursorPos[0], end: cursorPos[1] } ); |
| 391 | + } |
| 392 | + } |
| 393 | + |
395 | 394 | context.fn.updateHistory( event.data.scope == 'realchange' ); |
396 | 395 | return true; |
397 | 396 | }, |
— | — | @@ -489,7 +488,7 @@ |
490 | 489 | |
491 | 490 | // Restore cursor position |
492 | 491 | context.fn.purgeOffsets(); |
493 | | - var restoreTo = cursorPos[0] + context.fn.getContents().length - oldLength; |
| 492 | + var restoreTo = cursorPos[1] + context.fn.getContents().length - oldLength; |
494 | 493 | context.fn.setSelection( { start: restoreTo, end: restoreTo } ); |
495 | 494 | }, 0 ); |
496 | 495 | return true; |