From 8dc0b34fdc93cb4676941f14423d0b734f453bd9 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 15 Jan 2019 19:55:58 +0000 Subject: [PATCH] Desktop: Search engine: Improved support for JA, KO, ZH scripts --- ElectronClient/app/gui/NoteList.jsx | 2 +- ElectronClient/app/gui/NoteText.jsx | 4 ++-- ElectronClient/app/gui/note-viewer/index.html | 15 ++++++++++++--- ReactNativeClient/lib/services/SearchEngine.js | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ElectronClient/app/gui/NoteList.jsx b/ElectronClient/app/gui/NoteList.jsx index a9a3dfe80..4b537bcc1 100644 --- a/ElectronClient/app/gui/NoteList.jsx +++ b/ElectronClient/app/gui/NoteList.jsx @@ -284,7 +284,7 @@ class NoteListComponent extends React.Component { acrossElements: true, }); } else { - mark.mark([w], { + mark.mark([w.value], { accuracy: 'exactly', }); } diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index e21413ebb..be93e7ab5 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -6,7 +6,7 @@ const Search = require('lib/models/Search.js'); const { time } = require('lib/time-utils.js'); const Setting = require('lib/models/Setting.js'); const { IconButton } = require('./IconButton.min.js'); -const { urlDecode, escapeHtml, pregQuote } = require('lib/string-utils'); +const { urlDecode, escapeHtml, pregQuote, scriptType } = require('lib/string-utils'); const Toolbar = require('./Toolbar.min.js'); const TagList = require('./TagList.min.js'); const { connect } = require('react-redux'); @@ -734,7 +734,7 @@ class NoteTextComponent extends React.Component { webviewReady: true, }); - // if (Setting.value('env') === 'dev') this.webview_.openDevTools(); + if (Setting.value('env') === 'dev') this.webview_.openDevTools(); } webview_ref(element) { diff --git a/ElectronClient/app/gui/note-viewer/index.html b/ElectronClient/app/gui/note-viewer/index.html index afbe659d3..49a84f1e4 100644 --- a/ElectronClient/app/gui/note-viewer/index.html +++ b/ElectronClient/app/gui/note-viewer/index.html @@ -231,6 +231,8 @@ // TODO: It should highlight Russian // TODO: not working - "oue*" doesn't highlight "ouéé" // TODO: Search engine support to mobile app (sync tables) + // TODO: Update everywhere that uses allParsedQueryTerms to support new format + // TODO: Add support for scriptType on mobile and CLI if (!mark_) { mark_ = new Mark(document.getElementById('content'), { @@ -261,7 +263,7 @@ } for (let i = 0; i < keywords.length; i++) { - const keyword = keywords[i]; + let keyword = keywords[i]; if (typeof keyword === 'string') { keyword = { @@ -270,15 +272,22 @@ }; } + const isBasicSearch = ['ja', 'zh', 'ko'].indexOf(keyword.scriptType) >= 0; + if (keyword.type === 'regex') { - mark_.markRegExp(new RegExp('\\b' + keyword.value + '\\b', 'gmi'), { + let regexString = '\\b' + keyword.value + '\\b'; + if (isBasicSearch) regexString = keyword.value; + + mark_.markRegExp(new RegExp(regexString, 'gmi'), { each: onEachElement, acrossElements: true, }); } else { + let accuracy = keyword.accuracy ? keyword.accuracy : 'exactly'; + if (isBasicSearch) accuracy = 'partially'; mark_.mark([keyword.value], { each: onEachElement, - accuracy: keyword.accuracy ? keyword.accuracy : 'exactly', + accuracy: accuracy, }); } } diff --git a/ReactNativeClient/lib/services/SearchEngine.js b/ReactNativeClient/lib/services/SearchEngine.js index 4e7e07c04..a338d9a48 100644 --- a/ReactNativeClient/lib/services/SearchEngine.js +++ b/ReactNativeClient/lib/services/SearchEngine.js @@ -298,7 +298,9 @@ class SearchEngine { } if (term.indexOf('*') >= 0) { - terms[col][i] = { type: 'regex', value: this.queryTermToRegex(term) }; + terms[col][i] = { type: 'regex', value: this.queryTermToRegex(term), scriptType: scriptType(term) }; + } else { + terms[col][i] = { type: 'text', value: term, scriptType: scriptType(term) }; } }