Make hidden reasoning blocks not toggleable

93f3334ad0bb7b286ce9535d747d5034106bf018

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +18 -2Showing whitespace changes
public/scripts/reasoning.js+14 -2
@@ -153,7 +153,7 @@ export class ReasoningHandler {
153153 // Cached DOM elements for reasoning
154154 /** @type {HTMLElement} Main message DOM element `.mes` */
155155 this.messageDom = null;
156156 /** @type {HTMLElementHTMLDetailsElement} Reasoning details DOM element `.mes_reasoning_details` */
157157 this.messageReasoningDetailsDom = null;
158158 /** @type {HTMLElement} Reasoning content DOM element `.mes_reasoning` */
159159 this.messageReasoningContentDom = null;
@@ -336,6 +336,11 @@ export class ReasoningHandler {
336336 const button = this.messageDom.querySelector('.mes_edit_add_reasoning');
337337 button.title = this.state === ReasoningState.Hidden ? t`Hidden reasoning - Add reasoning block` : t`Add reasoning block`;
338338
339+ // Make sure that hidden reasoning headers are collapsed by default, to not show a useless edit button
340+ if (this.state === ReasoningState.Hidden) {
341+ this.messageReasoningDetailsDom.open = false;
342+ }
343+
339344 // Update the reasoning duration in the UI
340345 this.#updateReasoningTimeUI();
341346 }
@@ -628,7 +633,14 @@ function setReasoningEventHandlers() {
628633 }
629634 });
630635
631636 $(document).on('click', '.mes_reasoning_header', function (e) {
637+ const details = $(this).closest('.mes_reasoning_details');
638+ // Along with the CSS rules to mark blocks not toggle-able when they are empty, prevent them from actually being toggled, or being edited
639+ if (details.find('.mes_reasoning').is(':empty')) {
640+ e.preventDefault();
641+ return;
642+ }
643+
632644 // If we are in message edit mode and reasoning area is closed, a click opens and edits it
633645 const mes = $(this).closest('.mes');
634646 const mesEditArea = mes.find('#curEditTextarea');
public/style.css+4 -0
@@ -398,6 +398,10 @@ input[type='checkbox']:focus-visible {
398398 align-items: baseline;
399399}
400400
401+.mes:has(.mes_reasoning:empty) .mes_reasoning_header {
402+ cursor: default;
403+}
404+
401405/* TWIMC: Remove with custom CSS to show the icon */
402406.mes_reasoning_header > .icon-svg {
403407 display: none;