Rework reasoning CSS selectors and fixes - Remove reliance on :empty state of reasoning textbox, now using the actual css class on mes (".mes.reasoning") - Fix reasoning add not working when Auto-Expand is not enabled - Clean setting of dataset attributes, now removing when null
| @@ -13,7 +13,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | ||
| 13 | 13 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 14 | 14 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; |
| 15 | 15 | import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; |
| 16 | 16 | import { copyText, escapeRegex, isFalseBoolean, setDatasetProperty } from './utils.js'; |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Gets a message from a jQuery element. |
| @@ -323,8 +323,8 @@ export class ReasoningHandler { | ||
| 323 | 323 | this.messageDom.classList.toggle('reasoning', this.state !== ReasoningState.None); |
| 324 | 324 | |
| 325 | 325 | // Update states to the relevant DOM elements |
| 326 | 326 | setDatasetProperty(this.messageDom.dataset.reasoningState, ='reasoningState', this.state !== ReasoningState.None ? this.state : null); |
| 327 | 327 | setDatasetProperty(this.messageReasoningDetailsDom.dataset.state, ='state', this.state); |
| 328 | 328 | |
| 329 | 329 | // Update the reasoning message |
| 330 | 330 | const reasoning = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning; |
| @@ -391,8 +391,8 @@ export class ReasoningHandler { | ||
| 391 | 391 | data = null; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | setDatasetProperty(this.messageReasoningDetailsDom.dataset.duration, ='duration', data); |
| 395 | - element.dataset.duration = data; | |
| 395 | + setDatasetProperty(element, 'duration', data); | |
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| @@ -698,10 +698,9 @@ function setReasoningEventHandlers() { | ||
| 698 | 698 | const textarea = messageBlock.find('.reasoning_edit_textarea'); |
| 699 | 699 | textarea.remove(); |
| 700 | 700 | |
| 701 | 701 | // MakeIf surewe cancel, we might have to remove the fakereasong placeholderclass fromagain theif reasoningthis stringis an unsaved empty reasoning |
| 702 | - const text = messageBlock.find('.mes_reasoning').text(); | |
| 702 | + if (!messageBlock.attr('data--reasoning-state')) { | |
| 703 | - if (text === PromptReasoning.REASONING_UI_PLACEHOLDER) { | |
| 703 | + messageBlock.removeClass('reasoning'); | |
| 704 | - messageBlock.find('.mes_reasoning').text(''); | |
| 705 | 704 | } |
| 706 | 705 | |
| 707 | 706 | messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click'); |
| @@ -718,9 +717,10 @@ function setReasoningEventHandlers() { | ||
| 718 | 717 | return; |
| 719 | 718 | } |
| 720 | 719 | |
| 721 | - // To be able to edit, we need to "fake" content being there inside the reasoning string | |
| 720 | + messageBlock.addClass('reasoning'); | |
| 722 | - messageBlock.find('.mes_reasoning').text(PromptReasoning.REASONING_UI_PLACEHOLDER); | |
| 723 | 721 | |
| 722 | + // Open the reasoning area so we can actually edit it | |
| 723 | + messageBlock.find('.mes_reasoning_details').attr('open', ''); | |
| 724 | 724 | messageBlock.find('.mes_reasoning_edit').trigger('click'); |
| 725 | 725 | await saveChatConditional(); |
| 726 | 726 | }); |
| @@ -2059,6 +2059,23 @@ export function toggleDrawer(drawer, expand = true) { | ||
| 2059 | 2059 | } |
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | +/** | |
| 2063 | + * Sets or removes a dataset property on an HTMLElement | |
| 2064 | + * | |
| 2065 | + * Utility function to make it easier to reset dataset properties on null, without them being "null" as value. | |
| 2066 | + * | |
| 2067 | + * @param {HTMLElement} element - The element to modify | |
| 2068 | + * @param {string} name - The name of the dataset property | |
| 2069 | + * @param {string|null} value - The value to set - If null, the dataset property will be removed | |
| 2070 | + */ | |
| 2071 | +export function setDatasetProperty(element, name, value) { | |
| 2072 | + if (value === null) { | |
| 2073 | + delete element.dataset[name]; | |
| 2074 | + } else { | |
| 2075 | + element.dataset[name] = value; | |
| 2076 | + } | |
| 2077 | +} | |
| 2078 | + | |
| 2062 | 2079 | export async function fetchFaFile(name) { |
| 2063 | 2080 | const style = document.createElement('style'); |
| 2064 | 2081 | style.innerHTML = await (await fetch(`/css/${name}`)).text(); |
| @@ -410,17 +410,17 @@ input[type='checkbox']:focus-visible { | ||
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | .mes_bias:empty, |
| 413 | -.mes_reasoning:empty, | |
| 413 | +.mes:not(.reasoning) .mes_reasoning_details, | |
| 414 | -.mes_reasoning_details:has(.mes_reasoning:empty), | |
| 415 | 414 | .mes_reasoning_details:not([open]) .mes_reasoning_actions, |
| 416 | 415 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning, |
| 417 | 416 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_header, |
| 418 | -.mes_reasoning_details:not(:has(.reasoning_edit_textarea)) .mes_reasoning_actions .edit_button, | |
| 419 | 417 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_actions .mes_button:not(.edit_button), |
| 418 | +.mes_reasoning_details:not(:has(.reasoning_edit_textarea)) .mes_reasoning_actions .edit_button, | |
| 420 | 419 | .mes_block:has(.edit_textarea):has(.reasoning_edit_textarea) .mes_reasoning_actions, |
| 421 | 420 | .mes.reasoning:not([data-reasoning-state="none"]) .mes_edit_add_reasoning, |
| 422 | 421 | .mes[data-reasoning-state="nonehidden"] .mes_reasoning_arrow, |
| 423 | 422 | .mes[data-reasoning-state="nonehidden"] .mes_reasoning_actions {mes_reasoning, |
| 423 | +.mes[data-reasoning-state="hidden"] .mes_reasoning_copy { | |
| 424 | 424 | display: none; |
| 425 | 425 | } |
| 426 | 426 | |