Commit f51b630f45cbadef6273df197f1bbeecd968edb0
don't show preview if there is no room on screen
Matt McKegg committed on 10/17/2017, 1:06:36 AMParent: 19bf91406114f251a3218b5c45c4a69e95d11f84
Files changed
main-window.js | changed |
main-window.js | ||
---|---|---|
@@ -149,19 +149,26 @@ | ||
149 | 149 | } |
150 | 150 | |
151 | 151 | if (preview) { |
152 | 152 | var rect = element.getBoundingClientRect() |
153 | - var maxLeft = window.innerWidth - 510 | |
153 | + var width = 510 | |
154 | + var maxLeft = window.innerWidth - width | |
154 | 155 | var maxTop = window.innerHeight - 100 |
155 | 156 | var distanceFromRight = window.innerWidth - rect.right |
156 | 157 | var shouldDisplayBeside = rect.bottom > maxTop || rect.left < 100 || distanceFromRight < 100 |
157 | 158 | |
158 | 159 | if (shouldDisplayBeside && rect.bottom > 50) { |
159 | - preview.style.top = `${Math.min(rect.top, maxTop)}px` | |
160 | - if (rect.right > maxLeft) { | |
161 | - preview.style.left = `${rect.left - 510}px` | |
160 | + if (rect.right > maxLeft && (rect.left - width) < 0) { | |
161 | + // no room, just give up! | |
162 | + previewElement.set(null) | |
163 | + return | |
162 | 164 | } else { |
163 | - preview.style.left = `${rect.right + 5}px` | |
165 | + preview.style.top = `${Math.min(rect.top, maxTop)}px` | |
166 | + if (rect.right > maxLeft) { | |
167 | + preview.style.left = `${rect.left - width}px` | |
168 | + } else { | |
169 | + preview.style.left = `${rect.right + 5}px` | |
170 | + } | |
164 | 171 | } |
165 | 172 | } else { |
166 | 173 | preview.style.top = `${rect.bottom + 5}px` |
167 | 174 | preview.style.left = `${Math.min(rect.left, maxLeft)}px` |
Built with git-ssb-web