|
31 | 31 | describeSelectionForAt, |
32 | 32 | estimateSelectionBytes, |
33 | 33 | getLineSegmentBounds, |
| 34 | + isWholeFileSelection, |
34 | 35 | normaliseSelection, |
35 | 36 | } from './selection.svelte' |
36 | 37 | import { createViewerCopy } from './viewer-copy.svelte' |
|
182 | 183 | * the "unknown size" branch and confirm before reading). |
183 | 184 | */ |
184 | 185 | function estimateCurrentSelectionBytes(): number | null { |
| 186 | + const sel = selection.selection |
| 187 | + if (sel === null) return 0 |
| 188 | + // Whole-file shortcut: ⌘A on a multi-MB file selects lines the user never scrolled |
| 189 | + // through, so the line cache can't service the per-line walk. `totalBytes` is the |
| 190 | + // exact answer (it's the file size from `viewer_open`) and avoids the bail-to-null |
| 191 | + // that would otherwise route to the "unknown size" confirm dialog instead of the |
| 192 | + // correct refuse / confirm tier. |
| 193 | + if (isWholeFileSelection(sel, totalLines)) { |
| 194 | + return totalBytes |
| 195 | + } |
185 | 196 | return estimateSelectionBytes( |
186 | | - selection.selection, |
| 197 | + sel, |
187 | 198 | (n) => { |
188 | 199 | const txt = scroll.lineCache.get(n) |
189 | 200 | if (txt === undefined) return null |
|
1111 | 1122 | dialogId="viewer-copy-confirm" |
1112 | 1123 | titleId="viewer-copy-confirm-title" |
1113 | 1124 | onclose={cancelCopyConfirm} |
| 1125 | + containerStyle="max-width: 480px" |
1114 | 1126 | > |
1115 | 1127 | {#snippet title()} |
1116 | 1128 | <h2 id="viewer-copy-confirm-title" class="copy-dialog-title"> |
|
1121 | 1133 | {/if} |
1122 | 1134 | </h2> |
1123 | 1135 | {/snippet} |
1124 | | - <p class="copy-dialog-body"> |
1125 | | - Large pastes can slow down other apps. Try search (⌘F) to narrow it down. |
1126 | | - </p> |
1127 | | - <div class="copy-dialog-actions"> |
1128 | | - <Button variant="secondary" onclick={cancelCopyConfirm}>Cancel</Button> |
1129 | | - <Button |
1130 | | - variant="secondary" |
1131 | | - onclick={() => { |
1132 | | - void handleSaveAs() |
1133 | | - }}>Save as file…</Button |
1134 | | - > |
1135 | | - <Button |
1136 | | - variant="primary" |
1137 | | - onclick={() => { |
1138 | | - if (copyConfirmProceed) void copyConfirmProceed() |
1139 | | - }}>Copy</Button |
1140 | | - > |
| 1136 | + <div class="copy-dialog-body-wrap"> |
| 1137 | + <p class="copy-dialog-body"> |
| 1138 | + Large pastes can slow down other apps. Try search (⌘F) to narrow it down. |
| 1139 | + </p> |
| 1140 | + <div class="copy-dialog-actions"> |
| 1141 | + <Button variant="secondary" onclick={cancelCopyConfirm}>Cancel</Button> |
| 1142 | + <Button |
| 1143 | + variant="secondary" |
| 1144 | + onclick={() => { |
| 1145 | + void handleSaveAs() |
| 1146 | + }}>Save as file…</Button |
| 1147 | + > |
| 1148 | + <Button |
| 1149 | + variant="primary" |
| 1150 | + autoFocus |
| 1151 | + onclick={() => { |
| 1152 | + if (copyConfirmProceed) void copyConfirmProceed() |
| 1153 | + }}>Copy</Button |
| 1154 | + > |
| 1155 | + </div> |
1141 | 1156 | </div> |
1142 | 1157 | </ModalDialog> |
1143 | 1158 | {/if} |
|
1148 | 1163 | dialogId="viewer-copy-refuse" |
1149 | 1164 | titleId="viewer-copy-refuse-title" |
1150 | 1165 | onclose={dismissCopyRefuse} |
| 1166 | + containerStyle="max-width: 480px" |
1151 | 1167 | > |
1152 | 1168 | {#snippet title()} |
1153 | 1169 | <h2 id="viewer-copy-refuse-title" class="copy-dialog-title"> |
1154 | 1170 | Copy {formatBytes(refuseBytes)} to the clipboard? |
1155 | 1171 | </h2> |
1156 | 1172 | {/snippet} |
1157 | | - <p class="copy-dialog-body"> |
1158 | | - That's larger than the 100 MB clipboard limit. Try search (⌘F) to find what you need, or save the |
1159 | | - selection as a file. |
1160 | | - </p> |
1161 | | - <div class="copy-dialog-actions"> |
1162 | | - <Button variant="secondary" onclick={dismissCopyRefuse}>Cancel</Button> |
1163 | | - <Button |
1164 | | - variant="primary" |
1165 | | - onclick={() => { |
1166 | | - void handleSaveAs() |
1167 | | - }}>Save as file…</Button |
1168 | | - > |
| 1173 | + <div class="copy-dialog-body-wrap"> |
| 1174 | + <p class="copy-dialog-body"> |
| 1175 | + That's larger than the 100 MB clipboard limit. Try search (⌘F) to find what you need, or save the |
| 1176 | + selection as a file. |
| 1177 | + </p> |
| 1178 | + <div class="copy-dialog-actions"> |
| 1179 | + <Button variant="secondary" onclick={dismissCopyRefuse}>Cancel</Button> |
| 1180 | + <Button |
| 1181 | + variant="primary" |
| 1182 | + autoFocus |
| 1183 | + onclick={() => { |
| 1184 | + void handleSaveAs() |
| 1185 | + }}>Save as file…</Button |
| 1186 | + > |
| 1187 | + </div> |
1169 | 1188 | </div> |
1170 | 1189 | </ModalDialog> |
1171 | 1190 | {/if} |
|
1542 | 1561 | margin: 0; |
1543 | 1562 | } |
1544 | 1563 |
|
| 1564 | + /* Matches the AlertDialog body wrapper: design-system § Dialogs body padding 0 24px 24px. */ |
| 1565 | + .copy-dialog-body-wrap { |
| 1566 | + padding: 0 var(--spacing-xl) var(--spacing-xl); |
| 1567 | + } |
| 1568 | +
|
1545 | 1569 | .copy-dialog-body { |
1546 | 1570 | font-size: var(--font-size-md); |
1547 | 1571 | line-height: 1.4; |
1548 | 1572 | color: var(--color-text-secondary); |
1549 | | - margin-top: var(--spacing-md); |
| 1573 | + margin: 0 0 var(--spacing-xl); |
1550 | 1574 | } |
1551 | 1575 |
|
1552 | 1576 | .copy-dialog-actions { |
1553 | 1577 | display: flex; |
1554 | 1578 | gap: var(--spacing-md); |
1555 | 1579 | justify-content: flex-end; |
1556 | | - margin-top: var(--spacing-xl); |
1557 | 1580 | } |
1558 | 1581 | </style> |
0 commit comments