cursorUp moves the cursor up line(s)
(steps int)
| 398 | |
| 399 | // cursorUp moves the cursor up line(s) |
| 400 | func (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 |
no test coverage detected