Fix seekForward and seekBackward not handling length=0 case correctly

This commit is contained in:
toasted-nutbread 2019-11-08 19:24:33 -05:00
parent b059609670
commit fa963722a7

View File

@ -108,6 +108,10 @@ class TextSourceRange {
static seekForward(node, offset, length) { static seekForward(node, offset, length) {
const state = {node, offset, remainder: length, content: ''}; const state = {node, offset, remainder: length, content: ''};
if (length <= 0) {
return state;
}
const TEXT_NODE = Node.TEXT_NODE; const TEXT_NODE = Node.TEXT_NODE;
const ELEMENT_NODE = Node.ELEMENT_NODE; const ELEMENT_NODE = Node.ELEMENT_NODE;
let resetOffset = false; let resetOffset = false;
@ -166,6 +170,10 @@ class TextSourceRange {
static seekBackward(node, offset, length) { static seekBackward(node, offset, length) {
const state = {node, offset, remainder: length, content: ''}; const state = {node, offset, remainder: length, content: ''};
if (length <= 0) {
return state;
}
const TEXT_NODE = Node.TEXT_NODE; const TEXT_NODE = Node.TEXT_NODE;
const ELEMENT_NODE = Node.ELEMENT_NODE; const ELEMENT_NODE = Node.ELEMENT_NODE;
let resetOffset = false; let resetOffset = false;