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

Method iSpellKeyInput

texteditor/spell.go:120–200  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

118// iSpellKeyInput locates the word to spell check based on cursor position and
119// the key input, then passes the text region to SpellCheck
120func (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

Callers 1

keyInputMethod · 0.95

Calls 14

isWordEndMethod · 0.95
wordBeforeMethod · 0.95
spellCheckMethod · 0.95
isWordMiddleMethod · 0.95
wordAtMethod · 0.95
OfFunction · 0.92
IsWordBreakFunction · 0.92
isSpellEnabledMethod · 0.80
spellCheckLineTagMethod · 0.80
LineLenMethod · 0.80
KeyChordMethod · 0.65
LineMethod · 0.65

Tested by

no test coverage detected