* Handle clicks on the floating Rewrite button: open modal with selected text * @param {Object} app - Alpine app instance
(app)
| 126 | * @param {Object} app - Alpine app instance |
| 127 | */ |
| 128 | handleRewriteButtonClick(app) { |
| 129 | try { |
| 130 | // For textarea, use stored selection indices |
| 131 | const editor = document.querySelector('.editor-textarea'); |
| 132 | if (editor && editor.tagName === 'TEXTAREA') { |
| 133 | app.rewriteOriginalText = app.selectedTextForRewrite || ''; |
| 134 | // Keep the selection indices for later replacement |
| 135 | } else { |
| 136 | // Fallback for contenteditable (if ever used) |
| 137 | const selection = window.getSelection(); |
| 138 | if (selection && selection.rangeCount > 0) { |
| 139 | app.rewriteSelectionRange = selection.getRangeAt(0).cloneRange(); |
| 140 | app.rewriteOriginalText = selection.toString(); |
| 141 | } else { |
| 142 | app.rewriteOriginalText = app.selectedTextForRewrite || ''; |
| 143 | app.rewriteSelectionRange = null; |
| 144 | } |
| 145 | } |
| 146 | app.rewriteOutput = ''; |
| 147 | app.rewritePromptPreview = ''; |
| 148 | app.rewriteInProgress = false; |
| 149 | app.showRewriteModal = true; |
| 150 | app.showRewriteBtn = false; |
| 151 | } catch (e) { |
| 152 | console.error('handleRewriteButtonClick error', e); |
| 153 | } |
| 154 | }, |
| 155 | |
| 156 | /** |
| 157 | * Build the prompt for rewriting selected text |
nothing calls this directly
no outgoing calls
no test coverage detected