Better selection handling, fixing scan length being treated as a string.
This commit is contained in:
parent
14fd0d6514
commit
061cbb0141
@ -40,7 +40,7 @@ function formToOptions(section, callback) {
|
|||||||
|
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case 'general':
|
case 'general':
|
||||||
optsNew.scanLength = $('#scan-length').val();
|
optsNew.scanLength = parseInt($('#scan-length').val());
|
||||||
optsNew.activateOnStartup = $('#activate-on-startup').prop('checked');
|
optsNew.activateOnStartup = $('#activate-on-startup').prop('checked');
|
||||||
optsNew.loadEnamDict = $('#load-enamdict').prop('checked');
|
optsNew.loadEnamDict = $('#load-enamdict').prop('checked');
|
||||||
optsNew.selectMatchedText = $('#select-matched-text').prop('checked');
|
optsNew.selectMatchedText = $('#select-matched-text').prop('checked');
|
||||||
|
@ -38,6 +38,8 @@ function sanitizeOptions(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.scanLength = parseInt(options.scanLength);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,16 +27,29 @@ class Range {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLength(length) {
|
setLength(length) {
|
||||||
const node = this.rng.startContainer;
|
const end = this.findEnd(this.rng.startContainer, this.rng.startOffset, length);
|
||||||
const offset = this.rng.startOffset;
|
this.rng.setEnd(end.node, end.offset);
|
||||||
|
}
|
||||||
|
|
||||||
length = Math.min(node.length - offset, length);
|
findEnd(node, offset, length) {
|
||||||
if (length === 0) {
|
if (node.nodeType === 3) {
|
||||||
return null;
|
const remainder = node.data.length - offset;
|
||||||
|
if (remainder >= length) {
|
||||||
|
return {node, offset: offset + length};
|
||||||
|
}
|
||||||
|
|
||||||
|
length -= remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rng.setEnd(node, offset + length);
|
if (node.childNodes.length > 0) {
|
||||||
return length;
|
return this.findEnd(node.childNodes[0], 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.nextSibling !== null) {
|
||||||
|
return this.findEnd(node.nextSibling, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {node, offset: node.data.length};
|
||||||
}
|
}
|
||||||
|
|
||||||
containsPoint(point) {
|
containsPoint(point) {
|
||||||
|
Loading…
Reference in New Issue
Block a user