avelino/roam-tui

Move blocks up/down (reorder siblings)

Open

#6 opened on Feb 25, 2026

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Rust (0 forks)github user discovery
area: apiarea: editinggood first issuepriority: highroam parity

Repository metrics

Stars
 (21 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Summary

Allow reordering blocks among siblings by moving them up or down. This is a basic outliner operation present in Roam web and every outliner tool.

Roam web behavior: Cmd+Shift+Up / Cmd+Shift+Down moves the selected block up or down within its siblings, changing its order value.

TUI adaptation: Use Alt+Up / Alt+Down across all presets (consistent with most editors). Vim preset could also support K / J (shift+k/j) as alternatives.

Implementation hints

Existing pattern to follow

  • src/app.rs:1071handle_indent() is the closest pattern: it finds the block, computes new parent/order, applies locally, returns WriteAction::MoveBlock
  • src/app.rs:1122handle_dedent() same pattern
  • The new handle_move_up() / handle_move_down() functions should follow this exact structure

API

  • src/api/types.rs:111-115WriteAction::MoveBlock { block, location } already exists and supports this
  • Set location.parent_uid to same parent, location.order to order - 1 (move up) or order + 1 (move down)

Local state update

  • Find the block in state.days[].blocks tree
  • Swap order values with the sibling above/below
  • Reorder the children vec of the parent to reflect new order
  • Update selected_block index to follow the moved block

Edge cases

  • Block is first child → move up does nothing
  • Block is last child → move down does nothing
  • After move, the flat index changes — recalculate selected_block to track the block

Keybindings

  • src/keys/preset.rs — add new actions: MoveUp, MoveDown (or MoveBlockUp, MoveBlockDown to avoid confusion with cursor movement)
  • Map to Alt+Up / Alt+Down in all presets

Undo/redo

  • Add UndoEntry::MoveBlock variant or reuse existing one
  • Store: block_uid, old_parent_uid, old_order, selected_block

Acceptance criteria

  • Alt+Up moves block before its previous sibling
  • Alt+Down moves block after its next sibling
  • API receives MoveBlock write action
  • Selection follows the moved block
  • Undo/redo works for move operations
  • No-op at boundaries (first/last child)

Contributor guide