| 2134 | 2135 | name: 'goto-floor', |
| 2135 | 2136 | aliases: ['floor', 'jump', 'scrollto'], |
| 2136 | 2137 | callback: async (_, index) => { |
| 2137 | | - // --- Load all messages first to ensure the target element exists --- |
| 2138 | | - console.log(`INFO: Loading all messages before attempting to goto-floor ${index}.`); |
| 2139 | | - await showMoreMessages(Number.MAX_SAFE_INTEGER); |
| 2140 | | - console.log(`INFO: All messages loaded (or loading initiated).`); |
| 2141 | | - // --- End of loading step --- |
| 2142 | | - |
| 2143 | | - |
| 2144 | 2138 | const floorIndex = Number(index); |
| 2145 | 2139 | |
| 2146 | | - // Validate input |
| 2140 | + const chatLength = typeof chat !== 'undefined' ? chat.length : -1; // Use -1 if chat is undefined to avoid errors |
| 2147 | 2141 | if (isNaN(floorIndex) || floorIndex < 0 || (typeof chatchatLength !== 'undefined'-1 && floorIndex >= chat.lengthchatLength)) { |
| 2148 | 2142 | const maxIndex = (typeof chatchatLength !== 'undefined'-1 ? chat.lengthchatLength - 1 : 'unknown'); |
| 2149 | 2143 | toastr.warning(`Invalid message index: ${index}. Please enter a number between 0 and ${maxIndex}.`); |
| 2150 | 2144 | console.warn(`WARN: Invalid message index provided for /goto-floor: ${index}. Max index: ${maxIndex}`); |
| 2151 | 2145 | return ''; |
| 2152 | 2146 | } |
| 2153 | 2147 | |
| 2154 | 2148 | // Give--- theLoad renderingall amessages momentfirst to potentiallyensure catchthe uptarget afterelement showMoreMessagesexists --- |
| 2155 | | - // This might be necessary depending on how showMoreMessages works internally |
| 2149 | + console.log(`INFO: Attempting to load all messages before attempting to goto-floor ${index}.`); |
| 2156 | | - await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay if needed |
| 2150 | + try { |
| 2151 | + // Assuming showMoreMessages is available globally or within scope |
| 2152 | + await showMoreMessages(Number.MAX_SAFE_INTEGER); |
| 2153 | + console.log(`INFO: All messages loaded (or loading initiated).`); |
| 2154 | + // Give the rendering a moment to potentially catch up after showMoreMessages |
| 2155 | + await new Promise(resolve => setTimeout(resolve, 100)); // Adjust delay if needed |
| 2156 | + } catch (error) { |
| 2157 | + console.error('Error loading messages:', error); |
| 2158 | + toastr.error('An error occurred while trying to load messages.'); |
| 2159 | + return ''; // Exit if loading fails |
| 2160 | + } |
| 2161 | + // --- End of loading step --- |
| 2157 | 2162 | |
| 2158 | 2163 | const messageElement = document.querySelector(`[mesid="${floorIndex}"]`); |
| 2159 | 2164 | |
| 2160 | 2165 | if (messageElement) { |
| 2161 | | - const headerElement = messageElement.querySelector('.mes_header') || |
| 2166 | + // --- Corrected: Use the actual class from the template --- |
| 2162 | 2167 | const headerElement = messageElement.querySelector('.mes_metach_name') ||; |
| 2163 | | - messageElement.querySelector('.mes_name_area') || |
| 2168 | + const elementToScroll = headerElement || messageElement; // Fallback to the entire message div |
| 2164 | | - messageElement.querySelector('.mes_name'); |
| 2169 | + const blockPosition = headerElement ? 'center' : 'start'; |
| 2165 | | - |
| 2166 | | - const elementToScroll = headerElement || messageElement; // Prefer header, fallback to whole message |
| 2167 | | - const blockPosition = headerElement ? 'center' : 'start'; // Center header, else start of message |
| 2168 | 2170 | |
| 2169 | 2171 | elementToScroll.scrollIntoView({ behavior: 'smooth', block: blockPosition }); |
| 2170 | | - console.log(`INFO: Scrolled ${headerElement ? 'header of' : ''} message ${floorIndex} into view (block: ${blockPosition}).`); |
| 2171 | 2172 | |
| 2172 | 2173 | // --- Highlight with smooththe animationmessage ---element |
| 2173 | | - messageElement.classList.add('highlight-scroll'); |
| 2174 | + if (messageElement instanceof HTMLElement) { |
| 2174 | | - setTimeout(() => { |
| 2175 | + if (typeof $ !== 'undefined') { // Check if jQuery is available |
| 2175 | | - // Add a class to fade out, then remove the highlight class after fade |
| 2176 | + flashHighlight($(messageElement), 1500); |
| 2176 | | - messageElement.classList.add('highlight-scroll-fadeout'); |
| 2177 | + } else { |
| 2177 | | - // Wait for fadeout transition to complete before removing the base class |
| 2178 | + console.warn('jQuery not available, cannot use flashHighlight.'); |
| 2178 | | - // Match this duration to the transition duration in CSS |
| 2179 | + // Optional: Add a temporary CSS class highlight if jQuery/flashHighlight is missing |
| 2179 | | - setTimeout(() => { |
| 2180 | + messageElement.style.transition = 'background-color 0.5s ease'; |
| 2180 | | - messageElement.classList.remove('highlight-scroll', 'highlight-scroll-fadeout'); |
| 2181 | + messageElement.style.backgroundColor = 'yellow'; // Or some highlight color |
| 2181 | | - }, 500); // Matches the 0.5s transition duration |
| 2182 | + setTimeout(() => { |
| 2182 | | - }, 1500); // Start fade out after 1.5 seconds |
| 2183 | + messageElement.style.backgroundColor = ''; // Remove highlight |
| 2184 | + }, 1500); // Match flash duration |
| 2185 | + } |
| 2186 | + |
| 2187 | + } else { |
| 2188 | + console.warn('Message element is not an HTMLElement, cannot flash highlight.'); |
| 2189 | + } |
| 2190 | + |
| 2183 | 2191 | |
| 2184 | 2192 | } else { |
| 2185 | | - // This case is less likely now after showMoreMessages, but still possible |
| 2193 | + // Only warn if element is not found *after* attempting to load all messages |
| 2186 | | - // if the element hasn't been added to the DOM yet for some reason after loading. |
| 2194 | + toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]) even after attempting to load all messages. It might not be rendered yet or the index is invalid.`); |
| 2187 | | - toastr.warning(`Could not find element for message ${floorIndex} (using [mesid="${floorIndex}"]) even after attempting to load all messages. It might not be rendered yet. Try scrolling up or use /chat-render all again if issues persist.`); |
| 2188 | 2195 | console.warn(`WARN: Element not found for message index ${floorIndex} using querySelector [mesid="${floorIndex}"] in /goto-floor, even after attempting to load all messages.`); |
| 2189 | | - const chatContainer = document.getElementById('chat'); |
| 2196 | + // Do NOT scroll the chat container in this case |
| 2190 | | - if (chatContainer) { |
| 2191 | | - chatContainer.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
| 2192 | | - } |
| 2193 | 2197 | } |
| 2194 | | - return ''; |
| 2198 | + return ''; // Return empty string as expected by some slash command parsers |
| 2195 | 2199 | }, |
| 2196 | 2200 | unnamedArgumentList: [ |
| 2197 | 2201 | SlashCommandArgument.fromProps({ |