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

Method cursorUp

texteditor/nav.go:400–444  ·  view source on GitHub ↗

cursorUp moves the cursor up line(s)

(steps int)

Source from the content-addressed store, hash-verified

398
399// cursorUp moves the cursor up line(s)
400func (ed *Editor) cursorUp(steps int) {
401 ed.validateCursor()
402 org := ed.CursorPos
403 pos := ed.CursorPos
404 for i := 0; i < steps; i++ {
405 gotwrap := false
406 if wln := ed.wrappedLines(pos.Ln); wln > 1 {
407 si, ri, _ := ed.wrappedLineNumber(pos)
408 if si > 0 {
409 ri = ed.cursorColumn
410 nwc, _ := ed.renders[pos.Ln].SpanPosToRuneIndex(si-1, ri)
411 if nwc == pos.Ch {
412 ed.cursorColumn = 0
413 ri = 0
414 nwc, _ = ed.renders[pos.Ln].SpanPosToRuneIndex(si-1, ri)
415 }
416 pos.Ch = nwc
417 gotwrap = true
418 }
419 }
420 if !gotwrap {
421 pos.Ln--
422 if pos.Ln < 0 {
423 pos.Ln = 0
424 break
425 }
426 if wln := ed.wrappedLines(pos.Ln); wln > 1 { // just entered end of wrapped line
427 si := wln - 1
428 ri := ed.cursorColumn
429 nwc, _ := ed.renders[pos.Ln].SpanPosToRuneIndex(si, ri)
430 pos.Ch = nwc
431 } else {
432 mxlen := min(ed.Buffer.LineLen(pos.Ln), ed.cursorColumn)
433 if ed.cursorColumn < mxlen {
434 pos.Ch = ed.cursorColumn
435 } else {
436 pos.Ch = mxlen
437 }
438 }
439 }
440 }
441 ed.SetCursorShow(pos)
442 ed.cursorSelect(org)
443 ed.NeedsRender()
444}
445
446// cursorPageUp moves the cursor up page(s), where a page is defined
447// dynamically as just moving the cursor off the screen

Callers 1

keyInputMethod · 0.95

Calls 8

validateCursorMethod · 0.95
wrappedLinesMethod · 0.95
wrappedLineNumberMethod · 0.95
SetCursorShowMethod · 0.95
cursorSelectMethod · 0.95
SpanPosToRuneIndexMethod · 0.80
LineLenMethod · 0.80
NeedsRenderMethod · 0.80

Tested by

no test coverage detected