# Formula Reference Picking / dev-21.0.1

## Purpose

Formula editing should behave like a normal spreadsheet. When the user edits a formula such as `=SUM(` and then clicks or drags cells on the grid, UnifiedSpread must insert the clicked cell/range reference into the formula instead of moving the formula target cell.

## Implemented behavior

- In-cell formula editor:
  - Start editing a cell with a value beginning with `=`.
  - Click a cell to insert `A1` notation at the current caret position.
  - Drag across cells to replace the inserted reference with a range such as `A1:C5`.
  - The formula target cell is preserved until Enter commits or Esc cancels.

- Formula Bar:
  - Focus the Formula Bar while the value begins with `=`.
  - Click or drag cells to insert the reference into the Formula Bar text.
  - The original formula target selection is kept internally and commit writes back to that original cell.

## Design notes

The pointer gesture is implemented in `NativeGridRenderer` because it depends on DOM hit testing, auto-scroll and temporary visual overlays. The commit target is managed in `WorkbookService`, because the Formula Bar is part of the application chrome rather than the grid table itself.

Normal selection and formula reference picking are intentionally separate visual layers:

- `ng-selected` / `ng-range`: normal active selection.
- `ng-formula-ref-anchor` / `ng-formula-ref-range`: temporary reference highlight while editing a formula.

This avoids changing the active cell while a formula is being composed.
