Skip to content

Commit 036f7f8

Browse files
committed
Unfocus in-text editor when scrolled out of view
Closes marijnh#276
1 parent 411cc73 commit 036f7f8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

html/js/ejs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ window.addEventListener("load", () => {
9090
matchBrackets: true,
9191
lineNumbers: true
9292
})
93+
let pollingScroll = null
94+
function pollScroll() {
95+
if (document.activeElement != editor.getInputField()) return
96+
let rect = editor.getWrapperElement().getBoundingClientRect()
97+
if (rect.bottom < 0 || rect.top > innerHeight) editor.getInputField().blur()
98+
else pollingScroll = setTimeout(pollScroll, 500)
99+
}
100+
editor.on("focus", () => {
101+
clearTimeout(pollingScroll)
102+
pollingScroll = setTimeout(pollScroll, 500)
103+
})
93104
wrap.style.marginLeft = wrap.style.marginRight = -Math.min(article.offsetLeft, 100) + "px"
94105
setTimeout(() => editor.refresh(), 600)
95106
if (e) {

0 commit comments

Comments
 (0)