Refactor logic to improve setting correction panel dimensions
This commit is contained in:
parent
a105d4f1c2
commit
6c9629dec6
35
service.js
35
service.js
@ -173,7 +173,9 @@ class BesService {
|
||||
*/
|
||||
onFailedProofing(response) {
|
||||
delete this.abortController
|
||||
console.log(`Grammar checking failed: ${response.status} ${response.statusText}`)
|
||||
console.log(
|
||||
`Grammar checking failed: ${response.status} ${response.statusText}`
|
||||
)
|
||||
if (this.eventSink && 'failedProofing' in this.eventSink)
|
||||
this.eventSink.failedProofing(this, response)
|
||||
}
|
||||
@ -185,8 +187,7 @@ class BesService {
|
||||
*/
|
||||
onFailedProofingResult(error) {
|
||||
if (error !== 'AbortError') {
|
||||
if (!this.proofingError)
|
||||
this.proofingError = error
|
||||
if (!this.proofingError) this.proofingError = error
|
||||
console.log(`Failed to parse grammar checking results: ${error}`)
|
||||
}
|
||||
if (this.eventSink && 'failedProofingResult' in this.eventSink)
|
||||
@ -320,13 +321,8 @@ class BesService {
|
||||
|
||||
panelParent.appendChild(this.correctionPanel)
|
||||
this.correctionPanel.appendChild(this.scrollPanel)
|
||||
if (this.isHostElementInline()) {
|
||||
this.textElement.parentElement.insertBefore(panelParent, this.textElement)
|
||||
this.setCorrectionPanelSize()
|
||||
} else {
|
||||
document.body.insertBefore(panelParent, document.body.firstChild)
|
||||
this.setCorrectionPanelSize()
|
||||
}
|
||||
this.textElement.parentElement.insertBefore(panelParent, this.textElement)
|
||||
this.setCorrectionPanelSize()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -348,11 +344,12 @@ class BesService {
|
||||
this.correctionPanel.style.paddingLeft = styles.paddingLeft
|
||||
this.correctionPanel.style.paddingRight = styles.paddingRight
|
||||
this.scrollPanel.style.width = `${this.textElement.scrollWidth}px`
|
||||
this.scrollPanel.style.height = `${this.textElement.scrollHeight}px`
|
||||
const hStyles =
|
||||
this.hostElement !== this.textElement
|
||||
? window.getComputedStyle(this.hostElement)
|
||||
: styles
|
||||
if (this.isHostElementInline()) {
|
||||
const hStyles =
|
||||
this.hostElement !== this.textElement
|
||||
? window.getComputedStyle(this.hostElement)
|
||||
: styles
|
||||
const totalWidth =
|
||||
parseFloat(styles.paddingLeft) +
|
||||
parseFloat(styles.marginLeft) +
|
||||
@ -361,21 +358,13 @@ class BesService {
|
||||
parseFloat(styles.paddingRight)
|
||||
this.correctionPanel.style.width = `${totalWidth}px`
|
||||
this.correctionPanel.style.height = hStyles.height
|
||||
|
||||
this.scrollPanel.style.height = `${this.textElement.scrollHeight}px`
|
||||
} else {
|
||||
const rect = this.textElement.getBoundingClientRect()
|
||||
this.correctionPanel.style.width = styles.width
|
||||
|
||||
const totalHeight =
|
||||
parseFloat(styles.paddingTop) +
|
||||
parseFloat(styles.marginTop) +
|
||||
parseFloat(styles.height) +
|
||||
parseFloat(styles.marginBottom) +
|
||||
parseFloat(styles.paddingTop) +
|
||||
parseFloat(styles.paddingBottom)
|
||||
this.correctionPanel.style.height = `${totalHeight}px`
|
||||
this.correctionPanel.style.marginTop = `${rect.top + window.scrollY}px`
|
||||
this.scrollPanel.style.height = `${this.textElement.scrollHeight}px`
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user