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)
| 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. |
| 364 | func (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. |
no test coverage detected