MCPcopy Create free account
hub / github.com/cogentcore/core / spellCheck

Method spellCheck

texteditor/spell.go:204–228  ·  view source on GitHub ↗

spellCheck offers spelling corrections if we are at a word break or other word termination and the word before the break is unknown -- returns true if misspelled word found

(reg *text.Edit)

Source from the content-addressed store, hash-verified

202// spellCheck offers spelling corrections if we are at a word break or other word termination
203// and the word before the break is unknown -- returns true if misspelled word found
204func (ed *Editor) spellCheck(reg *text.Edit) bool {
205 if ed.Buffer.spell == nil {
206 return false
207 }
208 wb := string(reg.ToBytes())
209 lwb := lexer.FirstWordApostrophe(wb) // only lookup words
210 if len(lwb) <= 2 {
211 return false
212 }
213 widx := strings.Index(wb, lwb) // adjust region for actual part looking up
214 ld := len(wb) - len(lwb)
215 reg.Reg.Start.Ch += widx
216 reg.Reg.End.Ch += widx - ld
217
218 sugs, knwn := ed.Buffer.spell.checkWord(lwb)
219 if knwn {
220 ed.Buffer.RemoveTag(reg.Reg.Start, token.TextSpellErr)
221 return false
222 }
223 // fmt.Printf("spell err: %s\n", wb)
224 ed.Buffer.spell.setWord(wb, sugs, reg.Reg.Start.Ln, reg.Reg.Start.Ch)
225 ed.Buffer.RemoveTag(reg.Reg.Start, token.TextSpellErr)
226 ed.Buffer.AddTagEdit(reg, token.TextSpellErr)
227 return true
228}
229
230// offerCorrect pops up a menu of possible spelling corrections for word at
231// current CursorPos. If no misspelling there or not in spellcorrect mode

Callers 1

iSpellKeyInputMethod · 0.95

Calls 7

FirstWordApostropheFunction · 0.92
ToBytesMethod · 0.80
checkWordMethod · 0.80
RemoveTagMethod · 0.80
setWordMethod · 0.80
AddTagEditMethod · 0.80
IndexMethod · 0.45

Tested by

no test coverage detected