iSpellKeyInput locates the word to spell check based on cursor position and the key input, then passes the text region to SpellCheck
(kt events.Event)
| 118 | // iSpellKeyInput locates the word to spell check based on cursor position and |
| 119 | // the key input, then passes the text region to SpellCheck |
| 120 | func (ed *Editor) iSpellKeyInput(kt events.Event) { |
| 121 | if !ed.Buffer.isSpellEnabled(ed.CursorPos) { |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | isDoc := ed.Buffer.Info.Cat == fileinfo.Doc |
| 126 | tp := ed.CursorPos |
| 127 | |
| 128 | kf := keymap.Of(kt.KeyChord()) |
| 129 | switch kf { |
| 130 | case keymap.MoveUp: |
| 131 | if isDoc { |
| 132 | ed.Buffer.spellCheckLineTag(tp.Ln) |
| 133 | } |
| 134 | case keymap.MoveDown: |
| 135 | if isDoc { |
| 136 | ed.Buffer.spellCheckLineTag(tp.Ln) |
| 137 | } |
| 138 | case keymap.MoveRight: |
| 139 | if ed.isWordEnd(tp) { |
| 140 | reg := ed.wordBefore(tp) |
| 141 | ed.spellCheck(reg) |
| 142 | break |
| 143 | } |
| 144 | if tp.Ch == 0 { // end of line |
| 145 | tp.Ln-- |
| 146 | if isDoc { |
| 147 | ed.Buffer.spellCheckLineTag(tp.Ln) // redo prior line |
| 148 | } |
| 149 | tp.Ch = ed.Buffer.LineLen(tp.Ln) |
| 150 | reg := ed.wordBefore(tp) |
| 151 | ed.spellCheck(reg) |
| 152 | break |
| 153 | } |
| 154 | txt := ed.Buffer.Line(tp.Ln) |
| 155 | var r rune |
| 156 | atend := false |
| 157 | if tp.Ch >= len(txt) { |
| 158 | atend = true |
| 159 | tp.Ch++ |
| 160 | } else { |
| 161 | r = txt[tp.Ch] |
| 162 | } |
| 163 | if atend || core.IsWordBreak(r, rune(-1)) { |
| 164 | tp.Ch-- // we are one past the end of word |
| 165 | reg := ed.wordBefore(tp) |
| 166 | ed.spellCheck(reg) |
| 167 | } |
| 168 | case keymap.Enter: |
| 169 | tp.Ln-- |
| 170 | if isDoc { |
| 171 | ed.Buffer.spellCheckLineTag(tp.Ln) // redo prior line |
| 172 | } |
| 173 | tp.Ch = ed.Buffer.LineLen(tp.Ln) |
| 174 | reg := ed.wordBefore(tp) |
| 175 | ed.spellCheck(reg) |
| 176 | case keymap.FocusNext: |
| 177 | tp.Ch-- // we are one past the end of word |
no test coverage detected