GotoLoc moves the cursor to a new location and adjusts the view accordingly. Use GotoLoc when the new location may be far away from the current location.
(loc buffer.Loc)
| 360 | // GotoLoc moves the cursor to a new location and adjusts the view accordingly. |
| 361 | // Use GotoLoc when the new location may be far away from the current location. |
| 362 | func (h *BufPane) GotoLoc(loc buffer.Loc) { |
| 363 | sloc := h.SLocFromLoc(loc) |
| 364 | d := h.Diff(h.SLocFromLoc(h.Cursor.Loc), sloc) |
| 365 | |
| 366 | h.Cursor.GotoLoc(loc) |
| 367 | |
| 368 | // If the new location is far away from the previous one, |
| 369 | // ensure the cursor is at 25% of the window height |
| 370 | height := h.BufView().Height |
| 371 | if util.Abs(d) >= height { |
| 372 | v := h.GetView() |
| 373 | v.StartLine = h.Scroll(sloc, -height/4) |
| 374 | h.ScrollAdjust() |
| 375 | v.StartCol = 0 |
| 376 | } |
| 377 | h.Relocate() |
| 378 | } |
| 379 | |
| 380 | func (h *BufPane) initialRelocate() { |
| 381 | sloc := h.SLocFromLoc(h.Cursor.Loc) |
no test coverage detected