diff --git a/ext/css/material.css b/ext/css/material.css index 4d319349..6621df96 100644 --- a/ext/css/material.css +++ b/ext/css/material.css @@ -807,6 +807,10 @@ input[type=number].code, input[type=password].code { font-family: 'Courier New', Courier, monospace; } +textarea.no-wrap { + white-space: pre; + overflow-wrap: normal; +} /* Input groups */ .input-group { diff --git a/ext/css/settings.css b/ext/css/settings.css index 62e979e0..dc8132be 100644 --- a/ext/css/settings.css +++ b/ext/css/settings.css @@ -1628,8 +1628,8 @@ code.anki-field-marker { resize: none; min-height: calc(var(--textarea-line-height) * 5 + var(--textarea-padding) * 2); } -#anki-card-templates-render-result, -#anki-card-templates-compile-result { + +.code { flex: 0 0 auto; width: 100%; max-width: 100%; diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json index 215ca32c..279be153 100644 --- a/ext/data/schemas/options-schema.json +++ b/ext/data/schemas/options-schema.json @@ -791,7 +791,7 @@ }, "definitionsCollapsible": { "type": "string", - "enum": ["not-collapsible", "expanded", "collapsed"], + "enum": ["not-collapsible", "expanded", "collapsed", "force-collapsed", "force-expanded"], "default": "not-collapsible" } } diff --git a/ext/js/display/element-overflow-controller.js b/ext/js/display/element-overflow-controller.js index 0c6b3a71..04f26438 100644 --- a/ext/js/display/element-overflow-controller.js +++ b/ext/js/display/element-overflow-controller.js @@ -32,6 +32,7 @@ class ElementOverflowController { for (const {name, definitionsCollapsible} of options.dictionaries) { let collapsible = false; let collapsed = false; + let force = false; switch (definitionsCollapsible) { case 'expanded': collapsible = true; @@ -40,9 +41,18 @@ class ElementOverflowController { collapsible = true; collapsed = true; break; + case 'force-expanded': + collapsible = true; + force = true; + break; + case 'force-collapsed': + collapsible = true; + collapsed = true; + force = true; + break; } if (!collapsible) { continue; } - this._dictionaries.set(name, {collapsed}); + this._dictionaries.set(name, {collapsed, force}); } } @@ -50,14 +60,17 @@ class ElementOverflowController { if (this._dictionaries.size === 0) { return; } const elements = entry.querySelectorAll('.definition-item-inner'); - let any = false; for (const element of elements) { const {dictionary} = element.parentNode.dataset; const dictionaryInfo = this._dictionaries.get(dictionary); if (typeof dictionaryInfo === 'undefined') { continue; } - this._updateElement(element); - this._elements.push(element); + if (dictionaryInfo.force) { + element.classList.add('collapsible', 'collapsible-forced'); + } else { + this._updateElement(element); + this._elements.push(element); + } if (dictionaryInfo.collapsed) { element.classList.add('collapsed'); @@ -67,18 +80,15 @@ class ElementOverflowController { if (button !== null) { this._eventListeners.addEventListener(button, 'click', this._onToggleButtonClickBind, false); } - - any = true; } - if (any && this._windowEventListeners.size === 0) { + if (this._elements.length > 0 && this._windowEventListeners.size === 0) { this._windowEventListeners.addEventListener(window, 'resize', this._onWindowResizeBind, false); } } clearElements() { - if (this._elements.length === 0) { return; } - this._elements = []; + this._elements.length = 0; this._windowEventListeners.removeAllEventListeners(); } diff --git a/ext/settings.html b/ext/settings.html index 3284117f..64246fd6 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -2440,6 +2440,14 @@ +
+ Dictionary definitions can be collapsed if they exceed a certain line count, + which may be useful for dictionaries with long definitions. + The appearance can be customized using custom CSS. + More… +
+Card templates can be tested using the inputs below. @@ -3219,7 +3298,7 @@