MCPcopy Create free account
hub / github.com/B33pBeeps/redthread / snapPullToNote

Method snapPullToNote

internal/app/model.go:364–401  ·  view source on GitHub ↗

snapPullToNote walks the notes list and snaps the pull's target to the next (or previous, if dir=-1) note's pin position, skipping the source.

(dir int)

Source from the content-addressed store, hash-verified

362// snapPullToNote walks the notes list and snaps the pull's target to the
363// next (or previous, if dir=-1) note's pin position, skipping the source.
364func (m *model) snapPullToNote(dir int) {
365 notes := m.board.Notes
366 if len(notes) <= 1 {
367 return
368 }
369 // Find the note whose pin currently matches the target (if any).
370 curIdx := -1
371 for i, n := range notes {
372 if n.ID == m.pull.FromID {
373 continue
374 }
375 px, py := n.PinPos(m.board.Zoom)
376 if px == m.pull.TargetX && py == m.pull.TargetY {
377 curIdx = i
378 break
379 }
380 }
381 start := curIdx
382 if start < 0 {
383 // no current match — start before the first index in the dir we're going
384 if dir > 0 {
385 start = -1
386 } else {
387 start = len(notes)
388 }
389 }
390 for step := 1; step <= len(notes); step++ {
391 next := (start + dir*step) % len(notes)
392 for next < 0 {
393 next += len(notes)
394 }
395 if notes[next].ID != m.pull.FromID {
396 px, py := notes[next].PinPos(m.board.Zoom)
397 m.pull.SetTarget(px, py)
398 return
399 }
400 }
401}
402
403// handleRenameKey intercepts every keystroke while the user is editing a
404// board's name in the tab bar. Enter commits, esc cancels.

Callers 1

handlePullKeyMethod · 0.95

Calls 2

PinPosMethod · 0.80
SetTargetMethod · 0.80

Tested by

no test coverage detected