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

Method firstVisibleLine

texteditor/render.go:505–530  ·  view source on GitHub ↗

firstVisibleLine finds the first visible line, starting at given line (typically cursor -- if zero, a visible line is first found) -- returns stln if nothing found above it.

(stln int)

Source from the content-addressed store, hash-verified

503// (typically cursor -- if zero, a visible line is first found) -- returns
504// stln if nothing found above it.
505func (ed *Editor) firstVisibleLine(stln int) int {
506 bb := ed.renderBBox()
507 if stln == 0 {
508 perln := float32(ed.linesSize.Y) / float32(ed.NumLines)
509 stln = int(ed.Geom.Scroll.Y/perln) - 1
510 if stln < 0 {
511 stln = 0
512 }
513 for ln := stln; ln < ed.NumLines; ln++ {
514 lbb := ed.lineBBox(ln)
515 if int(math32.Ceil(lbb.Max.Y)) > bb.Min.Y { // visible
516 stln = ln
517 break
518 }
519 }
520 }
521 lastln := stln
522 for ln := stln - 1; ln >= 0; ln-- {
523 cpos := ed.charStartPos(lexer.Pos{Ln: ln})
524 if int(math32.Ceil(cpos.Y)) < bb.Min.Y { // top just offscreen
525 break
526 }
527 lastln = ln
528 }
529 return lastln
530}
531
532// lastVisibleLine finds the last visible line, starting at given line
533// (typically cursor) -- returns stln if nothing found beyond it.

Callers 2

cursorPageUpMethod · 0.95
PixelToCursorMethod · 0.95

Calls 4

renderBBoxMethod · 0.95
lineBBoxMethod · 0.95
charStartPosMethod · 0.95
CeilFunction · 0.92

Tested by

no test coverage detected