MCPcopy
hub / github.com/micro-editor/micro / GotoLoc

Method GotoLoc

internal/action/bufpane.go:362–378  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
362func (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
380func (h *BufPane) initialRelocate() {
381 sloc := h.SLocFromLoc(h.Cursor.Loc)

Callers 14

SearchMethod · 0.95
findMethod · 0.95
FindNextMethod · 0.95
FindPreviousMethod · 0.95
DiffNextMethod · 0.95
DiffPreviousMethod · 0.95
GotoCmdMethod · 0.95
JumpCmdMethod · 0.95
ReplaceCmdMethod · 0.95
CursorToViewTopMethod · 0.45
CursorToViewCenterMethod · 0.45
CursorToViewBottomMethod · 0.45

Calls 8

ScrollAdjustMethod · 0.95
AbsFunction · 0.92
SLocFromLocMethod · 0.65
DiffMethod · 0.65
BufViewMethod · 0.65
GetViewMethod · 0.65
ScrollMethod · 0.65
RelocateMethod · 0.65

Tested by

no test coverage detected