Compare commits
No commits in common. "16e85f5498c0e58c8819e3916140ec714043948e" and "156e6302e6acfe6c9bc80a9d733e5f1402fb1e14" have entirely different histories.
16e85f5498
...
156e6302e6
46
service.js
46
service.js
@ -312,8 +312,9 @@ class BesService {
|
|||||||
*/
|
*/
|
||||||
onScroll() {
|
onScroll() {
|
||||||
this.dismissPopup()
|
this.dismissPopup()
|
||||||
this.canvasPanel.style.top = `${-this.hostElement.scrollTop}px`
|
// Scroll panel is "position: absolute", we need to keep it aligned with the host element.
|
||||||
this.canvasPanel.style.left = `${-this.hostElement.scrollLeft}px`
|
this.scrollPanel.style.top = `${-this.hostElement.scrollTop}px`
|
||||||
|
this.scrollPanel.style.left = `${-this.hostElement.scrollLeft}px`
|
||||||
|
|
||||||
if (this.hostElement !== this.textElement) {
|
if (this.hostElement !== this.textElement) {
|
||||||
this.textElement.scrollTop = this.hostElement.scrollTop
|
this.textElement.scrollTop = this.hostElement.scrollTop
|
||||||
@ -335,6 +336,7 @@ class BesService {
|
|||||||
*/
|
*/
|
||||||
onResize() {
|
onResize() {
|
||||||
this.setCorrectionPanelSize()
|
this.setCorrectionPanelSize()
|
||||||
|
this.repositionAllMarkup()
|
||||||
if (this.eventSink && 'resize' in this.eventSink)
|
if (this.eventSink && 'resize' in this.eventSink)
|
||||||
this.eventSink.resize(this)
|
this.eventSink.resize(this)
|
||||||
}
|
}
|
||||||
@ -360,9 +362,9 @@ class BesService {
|
|||||||
*/
|
*/
|
||||||
addMistakeMarkup(match) {
|
addMistakeMarkup(match) {
|
||||||
const range = match.range
|
const range = match.range
|
||||||
const canvasPanelRect = this.canvasPanel.getBoundingClientRect()
|
const scrollPanelRect = this.scrollPanel.getBoundingClientRect()
|
||||||
const scrollX = canvasPanelRect.left
|
const scrollX = scrollPanelRect.left
|
||||||
const scrollY = canvasPanelRect.top
|
const scrollY = scrollPanelRect.top
|
||||||
match.highlights = Array.from(range.getClientRects())
|
match.highlights = Array.from(range.getClientRects())
|
||||||
if (match.highlights.length === 0) return
|
if (match.highlights.length === 0) return
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
@ -840,23 +842,24 @@ class BesService {
|
|||||||
* Creates auxiliary DOM elements for text adornments.
|
* Creates auxiliary DOM elements for text adornments.
|
||||||
*/
|
*/
|
||||||
createCorrectionPanel() {
|
createCorrectionPanel() {
|
||||||
this.panelParent = document.createElement('div')
|
const panelParent = document.createElement('div')
|
||||||
this.panelParent.classList.add('bes-correction-panel-parent')
|
panelParent.classList.add('bes-correction-panel-parent')
|
||||||
|
|
||||||
this.correctionPanel = document.createElement('div')
|
this.correctionPanel = document.createElement('div')
|
||||||
this.correctionPanel.classList.add('bes-correction-panel')
|
this.correctionPanel.classList.add('bes-correction-panel')
|
||||||
|
|
||||||
|
this.scrollPanel = document.createElement('div')
|
||||||
|
this.scrollPanel.classList.add('bes-correction-panel-scroll')
|
||||||
|
|
||||||
this.canvasPanel = document.createElement('canvas')
|
this.canvasPanel = document.createElement('canvas')
|
||||||
this.canvasPanel.classList.add('bes-canvas')
|
this.canvasPanel.classList.add('bes-canvas')
|
||||||
this.ctx = this.canvasPanel.getContext('2d')
|
this.ctx = this.canvasPanel.getContext('2d')
|
||||||
this.ctx.scale(1, 1)
|
this.ctx.scale(1, 1)
|
||||||
|
|
||||||
this.panelParent.appendChild(this.correctionPanel)
|
panelParent.appendChild(this.correctionPanel)
|
||||||
this.correctionPanel.appendChild(this.canvasPanel)
|
this.correctionPanel.appendChild(this.scrollPanel)
|
||||||
this.textElement.parentElement.insertBefore(
|
this.scrollPanel.appendChild(this.canvasPanel)
|
||||||
this.panelParent,
|
this.textElement.parentElement.insertBefore(panelParent, this.textElement)
|
||||||
this.textElement
|
|
||||||
)
|
|
||||||
this.setCorrectionPanelSize()
|
this.setCorrectionPanelSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -864,7 +867,9 @@ class BesService {
|
|||||||
* Clears auxiliary DOM elements for text adornments.
|
* Clears auxiliary DOM elements for text adornments.
|
||||||
*/
|
*/
|
||||||
clearCorrectionPanel() {
|
clearCorrectionPanel() {
|
||||||
this.panelParent.remove()
|
this.correctionPanel.remove()
|
||||||
|
this.scrollPanel.remove()
|
||||||
|
this.canvasPanel.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -874,13 +879,15 @@ class BesService {
|
|||||||
this.disableMutationObserver()
|
this.disableMutationObserver()
|
||||||
const styles = window.getComputedStyle(this.hostElement)
|
const styles = window.getComputedStyle(this.hostElement)
|
||||||
const hostRect = this.hostElement.getBoundingClientRect()
|
const hostRect = this.hostElement.getBoundingClientRect()
|
||||||
// Sync margins one by one. Firefox is not happy when syncing all at once.
|
|
||||||
this.correctionPanel.style.marginLeft = styles.marginLeft
|
this.correctionPanel.style.marginLeft = styles.marginLeft
|
||||||
this.correctionPanel.style.marginTop = styles.marginTop
|
this.correctionPanel.style.marginTop = styles.marginTop
|
||||||
this.correctionPanel.style.marginRight = styles.marginRight
|
this.correctionPanel.style.marginRight = styles.marginRight
|
||||||
this.correctionPanel.style.marginBottom = styles.marginBottom
|
this.correctionPanel.style.marginBottom = styles.marginBottom
|
||||||
this.correctionPanel.style.boxSizing = styles.boxSizing
|
this.correctionPanel.style.boxSizing = styles.boxSizing
|
||||||
this.correctionPanel.style.scrollBehavior = styles.scrollBehavior
|
this.correctionPanel.style.scrollBehavior = styles.scrollBehavior
|
||||||
|
this.correctionPanel.style.overflow = 'hidden'
|
||||||
|
this.scrollPanel.style.width = `${this.hostElement.scrollWidth}px`
|
||||||
|
this.scrollPanel.style.height = `${this.hostElement.scrollHeight}px`
|
||||||
this.canvasPanel.style.width = `${this.hostElement.scrollWidth}px`
|
this.canvasPanel.style.width = `${this.hostElement.scrollWidth}px`
|
||||||
this.canvasPanel.style.height = `${this.hostElement.scrollHeight}px`
|
this.canvasPanel.style.height = `${this.hostElement.scrollHeight}px`
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
@ -2245,14 +2252,6 @@ class BesTAService extends BesPlainTextService {
|
|||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters grammar checking service.
|
|
||||||
*/
|
|
||||||
unregister() {
|
|
||||||
super.unregister()
|
|
||||||
this.textElement.remove()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a clone div element for the <textarea> element
|
* Creates a clone div element for the <textarea> element
|
||||||
*
|
*
|
||||||
@ -2292,6 +2291,7 @@ class BesTAService extends BesPlainTextService {
|
|||||||
textElement.style.hyphens = styles.hyphens
|
textElement.style.hyphens = styles.hyphens
|
||||||
textElement.style.boxSizing = styles.boxSizing
|
textElement.style.boxSizing = styles.boxSizing
|
||||||
textElement.style.scrollBehavior = styles.scrollBehavior
|
textElement.style.scrollBehavior = styles.scrollBehavior
|
||||||
|
textElement.style.overflow = 'hidden'
|
||||||
textElement.style.border = styles.border
|
textElement.style.border = styles.border
|
||||||
textElement.style.borderRadius = styles.borderRadius
|
textElement.style.borderRadius = styles.borderRadius
|
||||||
textElement.style.padding = styles.padding
|
textElement.style.padding = styles.padding
|
||||||
|
@ -48,9 +48,12 @@
|
|||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bes-correction-panel-scroll {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
.bes-text-panel {
|
.bes-text-panel {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
overflow: hidden;
|
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
color: transparent;
|
color: transparent;
|
||||||
border-color: transparent;
|
border-color: transparent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user