Update function documentation
This commit is contained in:
parent
51099347f2
commit
d990cd061a
105
service.js
105
service.js
@ -357,7 +357,7 @@ class BesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates grammar mistake markup in DOM and populates collection of highlight rectangles.
|
* Draws grammar mistake markup on canvas and populates collection of highlight rectangles.
|
||||||
*
|
*
|
||||||
* @param {*} match Grammar checking rule match
|
* @param {*} match Grammar checking rule match
|
||||||
*/
|
*/
|
||||||
@ -663,21 +663,12 @@ class BesService {
|
|||||||
this.drawSideMarker(markerY1, markerY2)
|
this.drawSideMarker(markerY1, markerY2)
|
||||||
}
|
}
|
||||||
|
|
||||||
static commonPrefixLength(s1, s2) {
|
/**
|
||||||
let i = 0
|
* Draws the marker that helps visualize lines of text where grammar mistakes were detected
|
||||||
let len = Math.min(s1.length, s2.length)
|
*
|
||||||
while (i < len && s1[i] === s2[i]) i++
|
* @param {Number} y1 Marker top [px]
|
||||||
return i
|
* @param {Number} y2 Marker bottom [px]
|
||||||
}
|
*/
|
||||||
|
|
||||||
static commonSuffixLength(s1, s2) {
|
|
||||||
let i = 0
|
|
||||||
let i1 = s1.length
|
|
||||||
let i2 = s2.length
|
|
||||||
while (0 < i1-- && 0 < i2-- && s1[i1] === s2[i2]) i++
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
drawSideMarker(y1, y2) {
|
drawSideMarker(y1, y2) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
const markerX = this.canvasPanel.width - 5 * dpr
|
const markerX = this.canvasPanel.width - 5 * dpr
|
||||||
@ -687,6 +678,14 @@ class BesService {
|
|||||||
this.ctx.stroke()
|
this.ctx.stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the missing comma sign
|
||||||
|
*
|
||||||
|
* @param {Number} x Sign center [px]
|
||||||
|
* @param {Number} y Sign bottom [px]
|
||||||
|
* @param {Number} scale Sign scale
|
||||||
|
* @param {String} comment Text to display above the marker
|
||||||
|
*/
|
||||||
drawMissingComma(x, y, scale, comment) {
|
drawMissingComma(x, y, scale, comment) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -703,6 +702,14 @@ class BesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the wrong spacing sign. Control direction of chevrons by reversing y1 and y2.
|
||||||
|
*
|
||||||
|
* @param {Number} x Sign center [px]
|
||||||
|
* @param {Number} y1 Sign top/bottom [px]
|
||||||
|
* @param {Number} y2 Sign bottom/top [px]
|
||||||
|
* @param {Number} scale Sign scale
|
||||||
|
*/
|
||||||
drawWrongSpacing(x, y1, y2, scale) {
|
drawWrongSpacing(x, y1, y2, scale) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -717,6 +724,14 @@ class BesService {
|
|||||||
this.ctx.stroke()
|
this.ctx.stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strikes out the excessive text
|
||||||
|
*
|
||||||
|
* @param {Number} x1 Strike line start X [px]
|
||||||
|
* @param {Number} y1 Strike line start Y [px]
|
||||||
|
* @param {Number} x2 Strike line end X [px]
|
||||||
|
* @param {Number} y2 Strike line end Y [px]
|
||||||
|
*/
|
||||||
drawExcessiveText(x1, y1, x2, y2) {
|
drawExcessiveText(x1, y1, x2, y2) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -725,6 +740,16 @@ class BesService {
|
|||||||
this.ctx.stroke()
|
this.ctx.stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strikes out the text and draws the replacement text above
|
||||||
|
*
|
||||||
|
* @param {Number} x1 Strike line start X [px]
|
||||||
|
* @param {Number} y1 Strike line start Y [px]
|
||||||
|
* @param {Number} x2 Strike line end X [px]
|
||||||
|
* @param {Number} y2 Strike line end Y [px]
|
||||||
|
* @param {Number} scale Sign scale
|
||||||
|
* @param {String} text Text to display above
|
||||||
|
*/
|
||||||
drawWrongText(x1, y1, x2, y2, scale, text) {
|
drawWrongText(x1, y1, x2, y2, scale, text) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -749,6 +774,15 @@ class BesService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the sign some text is missing
|
||||||
|
*
|
||||||
|
* @param {Number} x Sign center [px]
|
||||||
|
* @param {Number} y1 Sign bottom [px]
|
||||||
|
* @param {Number} y2 Sign top [px]
|
||||||
|
* @param {Number} scale Sign scale
|
||||||
|
* @param {String} text Text to display above
|
||||||
|
*/
|
||||||
drawMissingText(x, y1, y2, scale, text) {
|
drawMissingText(x, y1, y2, scale, text) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -775,6 +809,14 @@ class BesService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws zig-zag line
|
||||||
|
*
|
||||||
|
* @param {Number} x1 Sign left [px]
|
||||||
|
* @param {Number} x2 Sign right [px]
|
||||||
|
* @param {Number} y Sign baseline [px]
|
||||||
|
* @param {Number} scale Sign scale
|
||||||
|
*/
|
||||||
drawAttentionRequired(x1, x2, y, scale) {
|
drawAttentionRequired(x1, x2, y, scale) {
|
||||||
const dpr = window.devicePixelRatio
|
const dpr = window.devicePixelRatio
|
||||||
this.ctx.beginPath()
|
this.ctx.beginPath()
|
||||||
@ -788,6 +830,35 @@ class BesService {
|
|||||||
this.ctx.stroke()
|
this.ctx.stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates common string prefix length
|
||||||
|
*
|
||||||
|
* @param {String} s1 First string
|
||||||
|
* @param {String} s2 Second string
|
||||||
|
* @returns Number of characters the beginnings of the strings are equal
|
||||||
|
*/
|
||||||
|
static commonPrefixLength(s1, s2) {
|
||||||
|
let i = 0
|
||||||
|
let len = Math.min(s1.length, s2.length)
|
||||||
|
while (i < len && s1[i] === s2[i]) i++
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates common string suffix length
|
||||||
|
*
|
||||||
|
* @param {String} s1 First string
|
||||||
|
* @param {String} s2 Second string
|
||||||
|
* @returns Number of characters the endings of the strings are equal
|
||||||
|
*/
|
||||||
|
static commonSuffixLength(s1, s2) {
|
||||||
|
let i = 0
|
||||||
|
let i1 = s1.length
|
||||||
|
let i2 = s2.length
|
||||||
|
while (0 < i1-- && 0 < i2-- && s1[i1] === s2[i2]) i++
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if given coordinate is inside of a rectangle.
|
* Tests if given coordinate is inside of a rectangle.
|
||||||
*
|
*
|
||||||
@ -899,7 +970,7 @@ class BesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes previously highlighted grammar mistake and highlights new one.
|
* Highlights given grammar mistake.
|
||||||
*
|
*
|
||||||
* @param {*} match Grammar checking rule match
|
* @param {*} match Grammar checking rule match
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user