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)
| 503 | // (typically cursor -- if zero, a visible line is first found) -- returns |
| 504 | // stln if nothing found above it. |
| 505 | func (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. |
no test coverage detected