summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-06 13:41:38 -0500
committerGitHub <noreply@github.com>2021-03-06 13:41:38 -0500
commit6e00b5d765dbcb580f93d1cdf6326169710cf36a (patch)
tree6c31f3b0511c0a339709aaf7338d598c312cc436 /ext
parent4bc53d2348bc07e1bad508de1ab9a8252bab10f4 (diff)
Fix multiline copying (#1493)
* Change order * Update multiline text assignment
Diffstat (limited to 'ext')
-rw-r--r--ext/js/display/display-generator.js30
1 files changed, 27 insertions, 3 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js
index bd0c83a2..93e84bdd 100644
--- a/ext/js/display/display-generator.js
+++ b/ext/js/display/display-generator.js
@@ -302,7 +302,7 @@ class DisplayGenerator {
_createTermGlossaryItemText(glossary) {
const node = this._templates.instantiate('glossary-item');
const container = node.querySelector('.glossary');
- this._setTextContent(container, glossary);
+ this._setMultilineTextContent(container, glossary);
return node;
}
@@ -350,7 +350,7 @@ class DisplayGenerator {
if (typeof description === 'string') {
const container = node.querySelector('.glossary-image-description');
- this._setTextContent(container, description);
+ this._setMultilineTextContent(container, description);
}
return node;
@@ -385,7 +385,7 @@ class DisplayGenerator {
_createKanjiGlossaryItem(glossary) {
const node = this._templates.instantiate('kanji-glossary-item');
const container = node.querySelector('.kanji-glossary');
- this._setTextContent(container, glossary);
+ this._setMultilineTextContent(container, glossary);
return node;
}
@@ -721,12 +721,36 @@ class DisplayGenerator {
}
_setTextContent(node, value, language) {
+ if (typeof language === 'string') {
+ node.lang = language;
+ } else if (this._japaneseUtil.isStringPartiallyJapanese(value)) {
+ node.lang = 'ja';
+ }
+
node.textContent = value;
+ }
+
+ _setMultilineTextContent(node, value, language) {
+ // This can't just call _setTextContent because the lack of <br> elements will
+ // cause the text to not copy correctly.
if (typeof language === 'string') {
node.lang = language;
} else if (this._japaneseUtil.isStringPartiallyJapanese(value)) {
node.lang = 'ja';
}
+
+ let start = 0;
+ while (true) {
+ const end = value.indexOf('\n', start);
+ if (end < 0) { break; }
+ node.appendChild(document.createTextNode(value.substring(start, end)));
+ node.appendChild(document.createElement('br'));
+ start = end + 1;
+ }
+
+ if (start < value.length) {
+ node.appendChild(document.createTextNode(start === 0 ? value : value.substring(start)));
+ }
}
_getPitchAccentCategories(pitches) {