www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 85ffc6b214f7c2c17c7c845f81fc555a6ad92af9
parent 8a4e7e88a429ec0a5c5dd8b68e38782db8897ed9
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 29 Mar 2011 00:40:11 +0000

- Do additional whitespace normalization when diffing items to prevent erroneous conflicts
- Save multiple whitespaces in TinyMCE as "&nbsp; " instead of "  " to prevent collapsing elsewhere
- Convert multiple spaces in plaintext notes (e.g., from 1.0) to "&nbsp; " instead of "&nbsp;&nbsp;"


Diffstat:
Mchrome/content/zotero/tinymce/note.html | 2+-
Mchrome/content/zotero/xpcom/data/item.js | 35++++++++++++++++++++++++++++-------
Mchrome/content/zotero/xpcom/utilities.js | 6++----
3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/chrome/content/zotero/tinymce/note.html b/chrome/content/zotero/tinymce/note.html @@ -12,7 +12,7 @@ content_css : "css/note-content.css", button_tile_map : true, language : "en", // TODO: localize - entity_encoding : "raw", + entities : "160,nbsp", gecko_spellcheck : true, handle_event_callback : function (event) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -3679,21 +3679,42 @@ Zotero.Item.prototype.diff = function (item, includeMatches, ignoreFields) { } if (thisData.note != undefined) { - // replace() keeps Windows newlines from triggering erroneous conflicts, - // though this should really be fixed at the data layer level + // Whitespace normalization // - // Using a try/catch to avoid unexpected errors in 2.1 Final + // Ideally this would all be fixed elsewhere so we didn't have to + // convert on every sync diff + // + // TEMP: Using a try/catch to avoid unexpected errors in 2.1 releases try { - changed = thisData.note.replace(/\r\n/g, "\n") != otherData.note.replace(/\r\n/g, "\n"); + var thisNote = thisData.note; + var otherNote = otherData.note; + + // Stop Windows newlines from triggering erroneous conflicts + thisNote = thisNote.replace(/\r\n/g, "\n"); + otherNote = otherNote.replace(/\r\n/g, "\n"); + + // Normalize multiple spaces (due to differences TinyMCE, Z.U.text2html(), + // and the server) + var re = /(&nbsp; |&nbsp;&nbsp;|\u00a0 |\u00a0\u00a0)/g; + thisNote = thisNote.replace(re, " "); + otherNote = otherNote.replace(re, " "); + + // Normalize new paragraphs + var re = /<p>(&nbsp;|\u00a0)<\/p>/g; + thisNote = thisNote.replace(re, "<p> </p>"); + otherNote = otherNote.replace(re, "<p> </p>"); + + changed = thisNote != otherNote; } catch (e) { Zotero.debug(e); Components.utils.reportError(e); - changed = thisData.note != otherData.note; + changed = thisNote != otherNote; } + if (includeMatches || changed) { - diff[0].note = thisData.note; - diff[1].note = otherData.note; + diff[0].note = thisNote; + diff[1].note = otherNote; } if (changed) { diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js @@ -159,8 +159,7 @@ Zotero.Utilities = { if (singleNewlineIsParagraph) { str = '<p>' + str.replace(/\n/g, '</p><p>') - .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') - .replace(/ /g, '&nbsp;&nbsp;') + .replace(/ /g, '&nbsp; ') + '</p>'; } // \n\n => <p>, \n => <br/> @@ -169,8 +168,7 @@ Zotero.Utilities = { str = '<p>' + str.replace(/\n\n/g, '</p><p>') .replace(/\n/g, '<br/>') - .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') - .replace(/ /g, '&nbsp;&nbsp;') + .replace(/ /g, '&nbsp; ') + '</p>'; } return str.replace(/<p>\s*<\/p>/g, '<p>&nbsp;</p>');