From 73ba66ea72d34badc25310bb03dce863011e8b62 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 12 Jul 2009 13:27:31 -0700 Subject: [PATCH] Fixed a Firefox 3.5 bug in which bold mode (or italics mode) would inexplicably end after typing a few characters. --- NEWS | 2 ++ static/js/Editor.js | 25 ++++++++++++++----------- static/js/Wiki.js | 31 +++++++++++++++++++------------ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index a3862d4..9f9f597 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ * Fixed a Firefox 3.5 bug in which after ending a link ctrl-L, typed text ended up as part of the link. Now, ctrl-L properly ends the link and any typed text after the link does not become linked itself. + * Fixed a Firefox 3.5 bug in which bold mode (or italics mode) would + inexplicably end after typing a few characters. 1.6.14: June 14, 2009 * Fixed a bug in which some printed or exported notes appeared in diff --git a/static/js/Editor.js b/static/js/Editor.js index b0cc8d8..b55b39e 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -941,17 +941,6 @@ Editor.prototype.key_released = function ( event ) { } Editor.prototype.cleanup_html = function ( key_code ) { - if ( this.iframe.contentWindow.getSelection ) { - var selection = this.iframe.contentWindow.getSelection(); - if ( selection.rangeCount > 0 ) - var range = selection.getRangeAt( 0 ); - else - var range = this.document.createRange(); - var fragment = range.cloneContents(); - if ( fragment.childNodes.length == 0 ) - this.exec_command( "removeformat" ); - } - if ( WEBKIT ) { // if enter is pressed while in a title, end title mode, since WebKit doesn't do that for us var ENTER = 13; BACKSPACE = 8; @@ -1041,6 +1030,20 @@ Editor.prototype.cleanup_html = function ( key_code ) { } } +Editor.prototype.cleanup_range = function () { + if ( !this.iframe.contentWindow.getSelection ) + return; + + var selection = this.iframe.contentWindow.getSelection(); + if ( selection.rangeCount > 0 ) + var range = selection.getRangeAt( 0 ); + else + var range = this.document.createRange(); + + if ( range.collapsed ) + this.exec_command( "removeformat" ); +} + Editor.prototype.unformat_selection = function () { if ( !this.iframe || !this.document ) return false; diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 5bd5f91..2e481a5 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -1478,10 +1478,13 @@ Wiki.prototype.toggle_button = function ( event, button_id ) { } Wiki.prototype.update_button = function ( button_id, state_name, node_names ) { - if ( state_name && node_names && this.focused_editor.state_enabled( state_name, node_names ) ) + if ( state_name && node_names && this.focused_editor.state_enabled( state_name, node_names ) ) { this.down_image_button( button_id ); - else - this.up_image_button( button_id ); + return 1; + } + + this.up_image_button( button_id ); + return 0; } Wiki.prototype.update_toolbar = function() { @@ -1497,16 +1500,20 @@ Wiki.prototype.update_toolbar = function() { link = this.focused_editor.find_link_at_cursor(); } + var enabled = 0; this.update_button( "newNote" ); - this.update_button( "bold", "b", node_names ); - this.update_button( "italic", "i", node_names ); - this.update_button( "underline", "u", node_names ); - this.update_button( "strikethrough", "strike", node_names ); - this.update_button( "color", "color", node_names ); - this.update_button( "font", "fontface", node_names ); - this.update_button( "title", "h3", node_names ); - this.update_button( "insertUnorderedList", "ul", node_names ); - this.update_button( "insertOrderedList", "ol", node_names ); + enabled += this.update_button( "bold", "b", node_names ); + enabled += this.update_button( "italic", "i", node_names ); + enabled += this.update_button( "underline", "u", node_names ); + enabled += this.update_button( "strikethrough", "strike", node_names ); + enabled += this.update_button( "color", "color", node_names ); + enabled += this.update_button( "font", "fontface", node_names ); + enabled += this.update_button( "title", "h3", node_names ); + enabled += this.update_button( "insertUnorderedList", "ul", node_names ); + enabled += this.update_button( "insertOrderedList", "ol", node_names ); + + if ( this.focused_editor && enabled == 0 ) + this.focused_editor.cleanup_range(); if ( link ) { // determine whether the link is a note link or a file link