Skip to content

Commit

Permalink
Updated lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Aug 25, 2014
1 parent a45fdc2 commit b01bb7c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 44 deletions.
6 changes: 3 additions & 3 deletions lib/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1007,4 +1007,4 @@
api.createCssClassApplier = api.createClassApplier = createClassApplier;
});

}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));
16 changes: 10 additions & 6 deletions lib/rangy-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3745,4 +3749,4 @@
}

return api;
}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));
6 changes: 3 additions & 3 deletions lib/rangy-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -598,4 +598,4 @@
};
});

}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));
6 changes: 3 additions & 3 deletions lib/rangy-selectionsaverestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -245,4 +245,4 @@
});
});

}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));
6 changes: 3 additions & 3 deletions lib/rangy-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -309,4 +309,4 @@
api.nodeToInfoString = nodeToInfoString;
});

}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));
66 changes: 40 additions & 26 deletions lib/rangy-textrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -491,12 +506,6 @@
}
};
}

/*
api.report = function() {
console.log("Cached: " + cachedCount + ", uncached: " + uncachedCount);
};
*/

/*----------------------------------------------------------------------------------------------------------------*/

Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -878,34 +894,32 @@
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 {
}
}
}

// 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);

Expand Down Expand Up @@ -1917,4 +1931,4 @@
};
});

}, this);
}, /* Ridiculous nonsense to get the global object in any environment follows */(function(f) { return f('return this;')(); })(Function));

0 comments on commit b01bb7c

Please sign in to comment.