diff --git a/static/js/Editor.js b/static/js/Editor.js index ac53b72..bb34818 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -250,25 +250,34 @@ Editor.prototype.init_iframe = function () { } this.document.open(); + var contents_text = this.contents(); + if ( !contents_text ) { + // hack: add a zero-width space to make the horizontal line under title show up in the + // correct position, even before there is a title + contents_text = "

​"; + } + this.document.write( '' + - '' + this.contents() + '' + '' + contents_text + '' ); this.document.close(); + + // move the text cursor to the end of the text + if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox + var selection = this.iframe.contentWindow.getSelection(); + var last_node = this.document.body.lastChild; + if ( last_node.nodeValue == "\n" && last_node.previousSibling ) + last_node = last_node.previousSibling; + + selection.selectAllChildren( last_node ); + selection.collapseToEnd(); + } else if ( this.document.selection ) { // browsers such as IE + var range = this.document.selection.createRange(); + } } Editor.prototype.finish_init = function () { - if ( !this.initial_text ) { - this.initial_text = "

"; - - // WebKit hack: add a zero-width space to make the horizontal line under title show up in the - // correct position, even before there is a title - if ( WEBKIT ) - this.initial_text += "​"; - } - -// this.insert_html( this.initial_text ); - // since the browser may subtly tweak the html when it's inserted, save off the browser's version // of the html here. this yields more accurate comparisons within the dirty() method if ( this.start_dirty )