Support rendering popup after scroll events
This commit is contained in:
parent
fe98c9237a
commit
06c88c37cd
@ -10,6 +10,7 @@ class BesEditor {
|
|||||||
const { correctionPanel, scrollPanel } = this.createCorrectionPanel(edit)
|
const { correctionPanel, scrollPanel } = this.createCorrectionPanel(edit)
|
||||||
this.correctionPanel = correctionPanel
|
this.correctionPanel = correctionPanel
|
||||||
this.scrollPanel = scrollPanel
|
this.scrollPanel = scrollPanel
|
||||||
|
this.offsetTop = null
|
||||||
this.proof(edit)
|
this.proof(edit)
|
||||||
edit.addEventListener('beforeinput', e => this.handleBeforeInput(e), false)
|
edit.addEventListener('beforeinput', e => this.handleBeforeInput(e), false)
|
||||||
edit.addEventListener('click', e => this.handleClick(e))
|
edit.addEventListener('click', e => this.handleClick(e))
|
||||||
@ -283,21 +284,30 @@ class BesEditor {
|
|||||||
popup.hide()
|
popup.hide()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (BesEditor.renderPopup(matches, popup, e.clientX, e.clientY)) return
|
if (
|
||||||
} else {
|
BesEditor.renderPopup(
|
||||||
popup.hide()
|
matches,
|
||||||
}
|
popup,
|
||||||
|
e.clientX,
|
||||||
|
e.clientY,
|
||||||
|
this.offsetTop
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
else popup.hide()
|
||||||
|
} else popup.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
handleScrollEvent(editor, scrollPanel) {
|
handleScrollEvent(editor, scrollPanel) {
|
||||||
scrollPanel.style.top = -editor.scrollTop + 'px'
|
scrollPanel.style.top = -editor.scrollTop + 'px'
|
||||||
|
this.offsetTop = editor.scrollTop
|
||||||
}
|
}
|
||||||
|
|
||||||
static renderPopup(matches, popup, clientX, clientY) {
|
static renderPopup(matches, popup, clientX, clientY, offsetTop) {
|
||||||
for (let m of matches) {
|
for (let m of matches) {
|
||||||
if (m.rects) {
|
if (m.rects) {
|
||||||
for (let r of m.rects) {
|
for (let r of m.rects) {
|
||||||
if (BesEditor.isPointInRect(clientX, clientY, r)) {
|
if (BesEditor.isPointInRect(clientX, clientY, r, offsetTop)) {
|
||||||
popup.changeText(m.match.message)
|
popup.changeText(m.match.message)
|
||||||
m.match.replacements.forEach(replacement => {
|
m.match.replacements.forEach(replacement => {
|
||||||
popup.appendReplacements(
|
popup.appendReplacements(
|
||||||
@ -336,13 +346,22 @@ class BesEditor {
|
|||||||
scrollPanel.style.height = editor.scrollHeight + 'px'
|
scrollPanel.style.height = editor.scrollHeight + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
static isPointInRect(x, y, rect) {
|
static isPointInRect(x, y, rect, offsetTop) {
|
||||||
|
if (!offsetTop) {
|
||||||
return (
|
return (
|
||||||
x >= rect.x &&
|
x >= rect.x &&
|
||||||
x < rect.x + rect.width &&
|
x < rect.x + rect.width &&
|
||||||
y >= rect.y &&
|
y >= rect.y &&
|
||||||
y < rect.y + rect.height
|
y < rect.y + rect.height
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
x >= rect.x &&
|
||||||
|
x < rect.x + rect.width &&
|
||||||
|
y >= rect.y - offsetTop &&
|
||||||
|
y < rect.y + rect.height - offsetTop
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user