Merge branch 'dev'
This commit is contained in:
commit
51092e2ff1
@ -20,28 +20,31 @@
|
|||||||
class TextSourceRange {
|
class TextSourceRange {
|
||||||
constructor(range) {
|
constructor(range) {
|
||||||
this.rng = range;
|
this.rng = range;
|
||||||
|
this.content = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
return new TextSourceRange(this.rng.cloneRange());
|
const tmp = new TextSourceRange(this.rng.cloneRange());
|
||||||
|
tmp.content = this.content;
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
text() {
|
text() {
|
||||||
return this.rng.toString();
|
return this.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
setEndOffset(length) {
|
setEndOffset(length) {
|
||||||
const lengthAdj = length + this.rng.startOffset;
|
const state = TextSourceRange.seekForward(this.rng.startContainer, this.rng.startOffset, length);
|
||||||
const state = TextSourceRange.seekForward(this.rng.startContainer, lengthAdj);
|
|
||||||
this.rng.setEnd(state.node, state.offset);
|
this.rng.setEnd(state.node, state.offset);
|
||||||
return length - state.length;
|
this.content = state.content;
|
||||||
|
return length - state.remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
setStartOffset(length) {
|
setStartOffset(length) {
|
||||||
const lengthAdj = length + (this.rng.startContainer.length - this.rng.startOffset);
|
const state = TextSourceRange.seekBackward(this.rng.startContainer, this.rng.startOffset, length);
|
||||||
const state = TextSourceRange.seekBackward(this.rng.startContainer, lengthAdj);
|
|
||||||
this.rng.setStart(state.node, state.offset);
|
this.rng.setStart(state.node, state.offset);
|
||||||
return length - state.length;
|
this.content = state.content;
|
||||||
|
return length - state.remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
containsPoint(point) {
|
containsPoint(point) {
|
||||||
@ -80,8 +83,13 @@ class TextSourceRange {
|
|||||||
return other.rng && other.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) === 0;
|
return other.rng && other.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static seekForward(node, length) {
|
static shouldEnter(node) {
|
||||||
const state = {node, length, offset: 0};
|
const skip = ['RT', 'SCRIPT', 'STYLE'];
|
||||||
|
return !skip.includes(node.nodeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
static seekForward(node, offset, length) {
|
||||||
|
const state = {node, offset, remainder: length, content: ''};
|
||||||
if (!TextSourceRange.seekForwardHelper(node, state)) {
|
if (!TextSourceRange.seekForwardHelper(node, state)) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -99,11 +107,14 @@ class TextSourceRange {
|
|||||||
|
|
||||||
static seekForwardHelper(node, state) {
|
static seekForwardHelper(node, state) {
|
||||||
if (node.nodeType === 3) {
|
if (node.nodeType === 3) {
|
||||||
const consumed = Math.min(node.length, state.length);
|
const offset = state.node === node ? state.offset : 0;
|
||||||
|
const remaining = node.length - offset;
|
||||||
|
const consumed = Math.min(remaining, state.remainder);
|
||||||
|
state.content = state.content + node.nodeValue.substring(offset, offset + consumed);
|
||||||
state.node = node;
|
state.node = node;
|
||||||
state.offset = consumed;
|
state.offset = offset + consumed;
|
||||||
state.length -= consumed;
|
state.remainder -= consumed;
|
||||||
} else {
|
} else if (TextSourceRange.shouldEnter(node)) {
|
||||||
for (let i = 0; i < node.childNodes.length; ++i) {
|
for (let i = 0; i < node.childNodes.length; ++i) {
|
||||||
if (!TextSourceRange.seekForwardHelper(node.childNodes[i], state)) {
|
if (!TextSourceRange.seekForwardHelper(node.childNodes[i], state)) {
|
||||||
break;
|
break;
|
||||||
@ -111,11 +122,11 @@ class TextSourceRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.length > 0;
|
return state.remainder > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static seekBackward(node, length) {
|
static seekBackward(node, offset, length) {
|
||||||
const state = {node, length, offset: node.length};
|
const state = {node, offset, remainder: length, content: ''};
|
||||||
if (!TextSourceRange.seekBackwardHelper(node, state)) {
|
if (!TextSourceRange.seekBackwardHelper(node, state)) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -133,11 +144,14 @@ class TextSourceRange {
|
|||||||
|
|
||||||
static seekBackwardHelper(node, state) {
|
static seekBackwardHelper(node, state) {
|
||||||
if (node.nodeType === 3) {
|
if (node.nodeType === 3) {
|
||||||
const consumed = Math.min(node.length, state.length);
|
const offset = state.node === node ? state.offset : node.length;
|
||||||
|
const remaining = offset;
|
||||||
|
const consumed = Math.min(remaining, state.remainder);
|
||||||
|
state.content = node.nodeValue.substring(offset - consumed, offset) + state.content;
|
||||||
state.node = node;
|
state.node = node;
|
||||||
state.offset = node.length - consumed;
|
state.offset = offset - consumed;
|
||||||
state.length -= consumed;
|
state.remainder -= consumed;
|
||||||
} else {
|
} else if (TextSourceRange.shouldEnter(node)) {
|
||||||
for (let i = node.childNodes.length - 1; i >= 0; --i) {
|
for (let i = node.childNodes.length - 1; i >= 0; --i) {
|
||||||
if (!TextSourceRange.seekBackwardHelper(node.childNodes[i], state)) {
|
if (!TextSourceRange.seekBackwardHelper(node.childNodes[i], state)) {
|
||||||
break;
|
break;
|
||||||
@ -145,6 +159,6 @@ class TextSourceRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.length > 0;
|
return state.remainder > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Yomichan",
|
"name": "Yomichan",
|
||||||
"version": "1.1.15",
|
"version": "1.1.16",
|
||||||
|
|
||||||
"description": "Japanese dictionary with Anki integration",
|
"description": "Japanese dictionary with Anki integration",
|
||||||
"icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"},
|
"icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"},
|
||||||
|
Loading…
Reference in New Issue
Block a user