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

Method cursorForwardWord

texteditor/nav.go:212–260  ·  view source on GitHub ↗

cursorForwardWord moves the cursor forward by words

(steps int)

Source from the content-addressed store, hash-verified

210
211// cursorForwardWord moves the cursor forward by words
212func (ed *Editor) cursorForwardWord(steps int) {
213 ed.validateCursor()
214 org := ed.CursorPos
215 for i := 0; i < steps; i++ {
216 txt := ed.Buffer.Line(ed.CursorPos.Ln)
217 sz := len(txt)
218 if sz > 0 && ed.CursorPos.Ch < sz {
219 ch := ed.CursorPos.Ch
220 var done = false
221 for ch < sz && !done { // if on a wb, go past
222 r1 := txt[ch]
223 r2 := rune(-1)
224 if ch < sz-1 {
225 r2 = txt[ch+1]
226 }
227 if core.IsWordBreak(r1, r2) {
228 ch++
229 } else {
230 done = true
231 }
232 }
233 done = false
234 for ch < sz && !done {
235 r1 := txt[ch]
236 r2 := rune(-1)
237 if ch < sz-1 {
238 r2 = txt[ch+1]
239 }
240 if !core.IsWordBreak(r1, r2) {
241 ch++
242 } else {
243 done = true
244 }
245 }
246 ed.CursorPos.Ch = ch
247 } else {
248 if ed.CursorPos.Ln < ed.NumLines-1 {
249 ed.CursorPos.Ch = 0
250 ed.CursorPos.Ln++
251 } else {
252 ed.CursorPos.Ch = ed.Buffer.LineLen(ed.CursorPos.Ln)
253 }
254 }
255 }
256 ed.setCursorColumn(ed.CursorPos)
257 ed.SetCursorShow(ed.CursorPos)
258 ed.cursorSelect(org)
259 ed.NeedsRender()
260}
261
262// cursorDown moves the cursor down line(s)
263func (ed *Editor) cursorDown(steps int) {

Callers 2

cursorDeleteWordMethod · 0.95
keyInputMethod · 0.95

Calls 8

validateCursorMethod · 0.95
setCursorColumnMethod · 0.95
SetCursorShowMethod · 0.95
cursorSelectMethod · 0.95
IsWordBreakFunction · 0.92
LineLenMethod · 0.80
NeedsRenderMethod · 0.80
LineMethod · 0.65

Tested by

no test coverage detected