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