Skip to content

Instantly share code, notes, and snippets.

View gariknyazev's full-sized avatar
🏠
Working from home

Igor Knyazev gariknyazev

🏠
Working from home
View GitHub Profile
@gariknyazev
gariknyazev / VisitTextNodesInRange.js
Created July 16, 2018 17:51
Visit all Text nodes in Range (JavaScript)
//Range definition https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
function visitTextNodesInRange(range, visitor) {
var reachedStartNode = false, reachedEndNode = false,
startContainer = range.startContainer, endContainer = range.endContainer,
startOffset = range.startOffset, endOffset = range.endOffset;
var visitNode = function (node, visitor) {
var isTextNode = node.nodeType === Node.TEXT_NODE;