Skip to content

Commit

Permalink
implement code block findNode/findOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Nov 9, 2015
1 parent 6234948 commit bb9833a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/formats/code-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ class CodeBlock extends Block {
hljs.highlightBlock(this.domNode);
}

findNode() {
return [this.domNode, 0]
findNode(index) {
let node, walker = document.createTreeWalker(this.domNode, NodeFilter.SHOW_TEXT, null, false);
while (node = walker.nextNode()) {
let length = node.data.length;
if (length > index) break;
index -= length;
}
return [node, index];
}

findOffset() {

findOffset(node) {
let cur, offset = 0, walker = document.createTreeWalker(this.domNode, NodeFilter.SHOW_TEXT, null, false);
while (cur = walker.nextNode()) {
if (cur === node) break;
offset += cur.data.length;
}
return offset;
}

format(name, value) {
Expand Down

0 comments on commit bb9833a

Please sign in to comment.