Skip to content

Commit 737a553

Browse files
feat: add new event highlgihtingChange for changes through spellcheck
1 parent 59962fe commit 737a553

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ You can check out a [simple demo on the website](https://livingdocsio.github.io/
4343
Fired when the cursor position changes.
4444
- **change**
4545
Fired when the user has made a change.
46+
- **spellcheckUpdated**
47+
Fired when the spellcheckService has updated the spellcheck highlights.
4648
- **clipboard**
4749
Fired for `copy`, `cut` and `paste` events.
4850
- **insert**

examples/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,22 @@ <h3>Example:</h3>
284284
editable.on('change', elem => {
285285
const currentContent = editable.getContent(elem);
286286
})
287+
</code></pre>
288+
</div>
289+
290+
</div>
291+
<div class="documentation">
292+
<h4>
293+
<span>spellcheckUpdated</span>
294+
</h4>
295+
<p>Fired when the spellcheckService has updated the spellcheck highlights.</p>
296+
297+
<div class="code-example">
298+
<h3>Example:</h3>
299+
<pre><code class="language-javascript">
300+
editable.on('spellcheckUpdated', elem => {
301+
const currentContent = editable.getContent(elem);
302+
})
287303
</code></pre>
288304
</div>
289305

spec/spellcheck.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ describe('Spellcheck:', function () {
5353
expect($(this.p).find('.misspelled-word').length).toEqual(1)
5454
})
5555

56+
it('notify spellcheckUpdated on add highlight through spellcheck', function () {
57+
let called = 0
58+
this.editable.on('spellcheckUpdated', () => called++)
59+
this.highlighting.highlight(this.p, true)
60+
expect(called).toEqual(1)
61+
})
62+
5663
it('removes a corrected highlighted match.', function () {
5764
this.highlighting.highlight(this.p)
5865
let $misspelledWord = $(this.p).find('.misspelled-word')

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ Editable.browser = browser
455455
// Set up callback functions for several events.
456456
;['focus', 'blur', 'flow', 'selection', 'cursor', 'newline',
457457
'insert', 'split', 'merge', 'empty', 'change', 'switch',
458-
'move', 'clipboard', 'paste'
458+
'move', 'clipboard', 'paste', 'spellcheckUpdated'
459459
].forEach((name) => {
460460
// Generate a callback function to subscribe to an event.
461461
Editable.prototype[name] = function (handler) {

src/highlighting.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export default class Highlighting {
135135

136136
this.safeHighlightMatches(editableHost, matchCollection.matches)
137137
})
138-
139138
}
140139

141140
// Calls highlightMatches internally but ensures
@@ -149,6 +148,9 @@ export default class Highlighting {
149148
} else {
150149
this.highlightMatches(editableHost, matches)
151150
}
151+
if (this.editable.dispatcher) {
152+
this.editable.dispatcher.notify('spellcheckUpdated', editableHost)
153+
}
152154
}
153155

154156
highlightMatches (editableHost, matches) {

0 commit comments

Comments
 (0)