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)
| 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 |
| 204 | func (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 |
no test coverage detected