aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/search-display-controller.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js
index b1e26750..20adbc82 100644
--- a/ext/js/display/search-display-controller.js
+++ b/ext/js/display/search-display-controller.js
@@ -21,6 +21,7 @@ import {ClipboardMonitor} from '../comm/clipboard-monitor.js';
import {createApiMap, invokeApiMapHandler} from '../core/api-map.js';
import {EventListenerCollection} from '../core/event-listener-collection.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
+import { escapeYomichanCopy } from '../refold-tools.js';
export class SearchDisplayController {
/**
@@ -36,6 +37,8 @@ export class SearchDisplayController {
/** @type {import('./search-persistent-state-controller.js').SearchPersistentStateController} */
this._searchPersistentStateController = searchPersistentStateController;
/** @type {HTMLButtonElement} */
+ this._copySentenceButton = querySelectorNotNull(document, '#anki-sentence-export-button');
+ /** @type {HTMLButtonElement} */
this._searchButton = querySelectorNotNull(document, '#search-button');
/** @type {HTMLButtonElement} */
this._searchBackButton = querySelectorNotNull(document, '#search-back-button');
@@ -101,6 +104,7 @@ export class SearchDisplayController {
this._display.queryParserVisible = true;
this._display.setHistorySettings({useBrowserHistory: true});
+ this._copySentenceButton.addEventListener('click', this._onCopySentence.bind(this), false);
this._searchButton.addEventListener('click', this._onSearch.bind(this), false);
this._searchBackButton.addEventListener('click', this._onSearchBackButtonClick.bind(this), false);
this._wanakanaEnableCheckbox.addEventListener('change', this._onWanakanaEnableChange.bind(this));
@@ -255,6 +259,37 @@ export class SearchDisplayController {
this._search(true, 'new', true, null);
}
+ /** @param {MouseEvent} e */
+ _onCopySentence(e) {
+ e.preventDefault();
+ var inputHTML = document.getElementById("query-parser-content");
+ var output = "";
+
+ var selection = window.getSelection();
+ // TODO: fix right-to-left selected text
+
+ for (var child of inputHTML.children) {
+ for (var subchild of child.childNodes) {
+ if (subchild.nodeName == '#text') {
+ for (var i in subchild.textContent) {
+ if (selection.anchorNode == subchild && i == selection.anchorOffset) output += "*";
+ output += subchild.textContent[i];
+ if (selection.focusNode == subchild && i == selection.focusOffset - 1) output += "*";
+ }
+ continue;
+ }
+ if (subchild.nodeName == 'RUBY') {
+ if (selection.anchorNode.parentNode.parentNode == subchild) output += "*";
+ output += `[${subchild.childNodes[0].innerText}](${subchild.childNodes[1].innerText})`;
+ if (selection.focusNode.parentNode.parentNode == subchild) output += "*";
+ continue;
+ }
+ }
+ }
+
+ escapeYomichanCopy(output);
+ }
+
/**
* @param {MouseEvent} e
*/