* Handles copying code from a code block * @param {HTMLElement} btn - The copy button element
(btn)
| 1164 | // Default path (non-Safari): DB-first to preserve raw markdown/LaTeX. |
| 1165 | const messages = await this.app.data.getSessionMessages(session.id); |
| 1166 | const message = messages.find(m => m.id === messageId); |
| 1167 | |
| 1168 | if (message && message.content && message.content.trim()) { |
| 1169 | this.copyToClipboard(message.content); |
| 1170 | this.showCopySuccess(messageId); |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | // Final fallback to visible DOM content. |
| 1175 | const domContent = this.getMessageTextFromDOM(messageId); |
| 1176 | if (domContent && domContent.trim()) { |
| 1177 | this.copyToClipboard(domContent); |
| 1178 | this.showCopySuccess(messageId); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | findCouncilLaneEntry(message, laneId) { |
| 1183 | const stageEntries = Array.isArray(message?.council?.stage1) |
| 1184 | ? message.council.stage1 |
| 1185 | : []; |
| 1186 | if (!laneId || stageEntries.length === 0) return null; |
| 1187 | return stageEntries.find((entry) => entry?.laneId === laneId) |
| 1188 | || stageEntries.find((entry) => entry?.label === laneId) |
| 1189 | || null; |
| 1190 | } |
| 1191 | |
| 1192 | async handleCopyCouncilLane(messageId, laneId, button = null) { |
| 1193 | const session = this.app.getCurrentSession(); |
| 1194 | if (!session || !messageId || !laneId) return; |
| 1195 | |
| 1196 | const messages = await this.app.data.getSessionMessages(session.id); |
| 1197 | const message = messages.find((entry) => entry.id === messageId); |
| 1198 | const laneEntry = this.findCouncilLaneEntry(message, laneId); |
| 1199 | const response = typeof laneEntry?.response === 'string' |
| 1200 | ? laneEntry.response |
| 1201 | : ''; |
| 1202 | |
| 1203 | if (!response.trim()) return; |
| 1204 | |
| 1205 | this.copyToClipboard(response); |
| 1206 | this.animateCopyButton(button || document.querySelector(`.copy-council-lane-btn[data-message-id="${messageId}"][data-council-lane-id="${laneId}"]`)); |
| 1207 | } |
| 1208 | |
| 1209 | /** |
| 1210 | * Shows copy success feedback on the appropriate button. |
| 1211 | * @param {string} messageId - The message ID |
| 1212 | */ |
| 1213 | showCopySuccess(messageId) { |
no test coverage detected