parent
e23d4b9a82
commit
658e5ddff1
@ -116,7 +116,7 @@ function docSentenceExtract(source, extent) {
|
|||||||
const sourceLocal = source.clone();
|
const sourceLocal = source.clone();
|
||||||
const position = sourceLocal.setStartOffset(extent);
|
const position = sourceLocal.setStartOffset(extent);
|
||||||
sourceLocal.setEndOffset(position + extent);
|
sourceLocal.setEndOffset(position + extent);
|
||||||
const content = sourceLocal.text();
|
const {text: content} = sourceLocal.text();
|
||||||
|
|
||||||
let quoteStack = [];
|
let quoteStack = [];
|
||||||
|
|
||||||
|
@ -311,10 +311,18 @@ class Frontend {
|
|||||||
async searchTerms(textSource) {
|
async searchTerms(textSource) {
|
||||||
textSource.setEndOffset(this.options.scanning.length);
|
textSource.setEndOffset(this.options.scanning.length);
|
||||||
|
|
||||||
const {definitions, length} = await apiTermsFind(textSource.text());
|
const {text, strippedIndices} = textSource.text();
|
||||||
|
let {definitions, length} = await apiTermsFind(text);
|
||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for (let index of strippedIndices) {
|
||||||
|
if (index < length) {
|
||||||
|
length++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
textSource.setEndOffset(length);
|
textSource.setEndOffset(length);
|
||||||
|
|
||||||
@ -338,7 +346,8 @@ class Frontend {
|
|||||||
async searchKanji(textSource) {
|
async searchKanji(textSource) {
|
||||||
textSource.setEndOffset(1);
|
textSource.setEndOffset(1);
|
||||||
|
|
||||||
const definitions = await apiKanjiFind(textSource.text());
|
const {text} = textSource.text();
|
||||||
|
const definitions = await apiKanjiFind(text);
|
||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// \u200c (Zero-width non-joiner) appears on Google Docs from Chrome 76 onwards
|
||||||
|
const IGNORE_TEXT_PATTERN = /\u200c/g;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TextSourceRange
|
* TextSourceRange
|
||||||
@ -32,7 +35,13 @@ class TextSourceRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
text() {
|
text() {
|
||||||
return this.content;
|
let strippedIndices = [];
|
||||||
|
const text = this.content.replace(IGNORE_TEXT_PATTERN, (match, offset) => {
|
||||||
|
strippedIndices.push(offset);
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
return {text, strippedIndices};
|
||||||
}
|
}
|
||||||
|
|
||||||
setEndOffset(length) {
|
setEndOffset(length) {
|
||||||
@ -195,7 +204,13 @@ class TextSourceElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
text() {
|
text() {
|
||||||
return this.content;
|
let strippedIndices = [];
|
||||||
|
const text = this.content.replace(IGNORE_TEXT_PATTERN, (match, offset) => {
|
||||||
|
strippedIndices.push(offset);
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
return {text, strippedIndices};
|
||||||
}
|
}
|
||||||
|
|
||||||
setEndOffset(length) {
|
setEndOffset(length) {
|
||||||
|
@ -83,7 +83,8 @@ class Display {
|
|||||||
const textSource = docRangeFromPoint({x: e.clientX, y: e.clientY});
|
const textSource = docRangeFromPoint({x: e.clientX, y: e.clientY});
|
||||||
textSource.setEndOffset(this.options.scanning.length);
|
textSource.setEndOffset(this.options.scanning.length);
|
||||||
|
|
||||||
const {definitions, length} = await apiTermsFind(textSource.text());
|
const {text} = textSource.text();
|
||||||
|
const {definitions, length} = await apiTermsFind(text);
|
||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user