diff --git a/lib/rangy-classapplier.js b/lib/rangy-classapplier.js index 547e9ef5..f63a52f4 100644 --- a/lib/rangy-classapplier.js +++ b/lib/rangy-classapplier.js @@ -9,8 +9,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ (function(factory, global) { if (typeof define == "function" && define.amd) { @@ -1007,4 +1007,4 @@ api.createCssClassApplier = api.createClassApplier = createClassApplier; }); -}, this); \ No newline at end of file +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); \ No newline at end of file diff --git a/lib/rangy-core.js b/lib/rangy-core.js index fd3521fb..c1ce5840 100644 --- a/lib/rangy-core.js +++ b/lib/rangy-core.js @@ -4,8 +4,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ (function(factory, global) { @@ -98,7 +98,7 @@ }; var api = { - version: "1.3.0-alpha.20140822.2", + version: "1.3.0-alpha.20140825", initialized: false, isBrowser: isBrowser, supported: true, @@ -2311,7 +2311,7 @@ /*--------------------------------------------------------------------------------------------------------*/ - // Test for IE 9 deleteContents() and extractContents() bug and correct it. See issue 107. + // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107. var el = document.createElement("div"); el.innerHTML = "123"; @@ -3205,7 +3205,11 @@ // Clone the native range so that changing the selected range does not affect the selection. // This is contrary to the spec but is the only way to achieve consistency between browsers. See // issue 80. - this.nativeSelection.addRange(getNativeRange(range).cloneRange()); + var clonedNativeRange = getNativeRange(range).cloneRange(); + try { + this.nativeSelection.addRange(clonedNativeRange); + } catch (ex) { + } // Check whether adding the range was successful this.rangeCount = this.nativeSelection.rangeCount; @@ -3745,4 +3749,4 @@ } return api; -}, this); \ No newline at end of file +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); \ No newline at end of file diff --git a/lib/rangy-highlighter.js b/lib/rangy-highlighter.js index 61e71771..badc28d7 100644 --- a/lib/rangy-highlighter.js +++ b/lib/rangy-highlighter.js @@ -6,8 +6,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ (function(factory, global) { if (typeof define == "function" && define.amd) { @@ -598,4 +598,4 @@ }; }); -}, this); +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); diff --git a/lib/rangy-selectionsaverestore.js b/lib/rangy-selectionsaverestore.js index a2eda336..f7a81533 100644 --- a/lib/rangy-selectionsaverestore.js +++ b/lib/rangy-selectionsaverestore.js @@ -9,8 +9,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ (function(factory, global) { if (typeof define == "function" && define.amd) { @@ -245,4 +245,4 @@ }); }); -}, this); \ No newline at end of file +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); \ No newline at end of file diff --git a/lib/rangy-serializer.js b/lib/rangy-serializer.js index 2fb6d85d..0b887091 100644 --- a/lib/rangy-serializer.js +++ b/lib/rangy-serializer.js @@ -10,8 +10,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ (function(factory, global) { if (typeof define == "function" && define.amd) { @@ -309,4 +309,4 @@ api.nodeToInfoString = nodeToInfoString; }); -}, this); \ No newline at end of file +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); \ No newline at end of file diff --git a/lib/rangy-textrange.js b/lib/rangy-textrange.js index b4e249a1..1429d0d0 100644 --- a/lib/rangy-textrange.js +++ b/lib/rangy-textrange.js @@ -26,8 +26,8 @@ * * Copyright 2014, Tim Down * Licensed under the MIT license. - * Version: 1.3.0-alpha.20140822.2 - * Build date: 22 August 2014 + * Version: 1.3.0-alpha.20140825 + * Build date: 25 August 2014 */ /** @@ -182,8 +182,23 @@ includeBlockContentTrailingSpace: true, includeSpaceBeforeBr: true, includeSpaceBeforeBlock: true, - includePreLineTrailingSpace: true + includePreLineTrailingSpace: true, + ignoreCharacters: "" }; + + function normalizeIgnoredCharacters(ignoredCharacters) { + // Check if character is ignored + var ignoredChars = ignoredCharacters || ""; + + // Normalize ignored characters into a string consisting of characters in ascending order of character code + var ignoredCharsArray = (typeof ignoredChars == "string") ? ignoredChars.split("") : ignoredChars; + ignoredCharsArray.sort(function(char1, char2) { + return char1.charCodeAt(0) - char2.charCodeAt(0); + }); + + /// Convert back to a string and remove duplicates + return ignoredCharsArray.join("").replace(/(.)\1+/g, "$1"); + } var defaultCaretCharacterOptions = { includeBlockContentTrailingSpace: !trailingSpaceBeforeLineBreakInPreLineCollapses, @@ -491,12 +506,6 @@ } }; } - - /* - api.report = function() { - console.log("Cached: " + cachedCount + ", uncached: " + uncachedCount); - }; - */ /*----------------------------------------------------------------------------------------------------------------*/ @@ -813,13 +822,20 @@ getCharacter: function(characterOptions) { this.resolveLeadingAndTrailingSpaces(); + var thisChar = this.character, returnChar; + + // Check if character is ignored + var ignoredChars = normalizeIgnoredCharacters(characterOptions.ignoreCharacters); + var isIgnoredCharacter = (thisChar !== "" && ignoredChars.indexOf(thisChar) > -1); + // Check if this position's character is invariant (i.e. not dependent on character options) and return it // if so if (this.isCharInvariant) { - return this.character; + returnChar = isIgnoredCharacter ? "" : thisChar; + return returnChar; } - var cacheKey = ["character", characterOptions.includeSpaceBeforeBr, characterOptions.includeBlockContentTrailingSpace, characterOptions.includePreLineTrailingSpace].join("_"); + var cacheKey = ["character", characterOptions.includeSpaceBeforeBr, characterOptions.includeBlockContentTrailingSpace, characterOptions.includePreLineTrailingSpace, ignoredChars].join("_"); var cachedChar = this.cache.get(cacheKey); if (cachedChar !== null) { return cachedChar; @@ -829,7 +845,7 @@ var character = ""; var collapsible = (this.characterType == COLLAPSIBLE_SPACE); - var nextPos, previousPos/* = this.getPrecedingUncollapsedPosition(characterOptions)*/; + var nextPos, previousPos; var gotPreviousPos = false; var pos = this; @@ -844,11 +860,11 @@ // Disallow a collapsible space that is followed by a line break or is the last character if (collapsible) { // Disallow a collapsible space that follows a trailing space or line break, or is the first character - if (this.character == " " && + if (thisChar == " " && (!getPreviousPos() || previousPos.isTrailingSpace || previousPos.character == "\n")) { } // Allow a leading line break unless it follows a line break - else if (this.character == "\n" && this.isLeadingSpace) { + else if (thisChar == "\n" && this.isLeadingSpace) { if (getPreviousPos() && previousPos.character != "\n") { character = "\n"; } else { @@ -864,12 +880,12 @@ this.type = TRAILING_SPACE_BEFORE_BLOCK; } - if (nextPos.character === "\n") { + if (nextPos.character == "\n") { if (this.type == TRAILING_SPACE_BEFORE_BR && !characterOptions.includeSpaceBeforeBr) { } else if (this.type == TRAILING_SPACE_BEFORE_BLOCK && !characterOptions.includeSpaceBeforeBlock) { } else if (this.type == TRAILING_SPACE_IN_BLOCK && nextPos.isTrailingSpace && !characterOptions.includeBlockContentTrailingSpace) { } else if (this.type == PRE_LINE_TRAILING_SPACE_BEFORE_LINE_BREAK && nextPos.type == NON_SPACE && !characterOptions.includePreLineTrailingSpace) { - } else if (this.character === "\n") { + } else if (thisChar == "\n") { if (nextPos.isTrailingSpace) { if (this.isTrailingSpace) { } else if (this.isBr) { @@ -878,23 +894,17 @@ if (getPreviousPos() && previousPos.isLeadingSpace && previousPos.character == "\n") { nextPos.character = ""; } else { - //character = "\n"; - //nextPos - /* - nextPos.character = ""; - character = "\n"; - */ } } } else { character = "\n"; } - } else if (this.character === " ") { + } else if (thisChar == " ") { character = " "; } else { } } else { - character = this.character; + character = thisChar; } } else { } @@ -902,10 +912,14 @@ } // Collapse a br element that is followed by a trailing space - else if (this.character === "\n" && + else if (thisChar == "\n" && (!(nextPos = this.nextUncollapsed()) || nextPos.isTrailingSpace)) { } + if (ignoredChars.indexOf(character) > -1) { + character = ""; + } + this.cache.set(cacheKey, character); @@ -1917,4 +1931,4 @@ }; }); -}, this); \ No newline at end of file +}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function)); \ No newline at end of file