# Filling

> Filling cells from the cells beside them: repeated as they are, or continued where there is one way to continue them.

Filling gives cells the values of the cells beside them: a block dragged out by
its corner, or told to fill down or across. It is how a value is repeated down a
column, and how a series is carried on, without typing each one.

## Best practices

**Fill along one axis.** A fill runs down or up the rows, or along the columns —
never both at once. A corner dragged diagonally fills the way it has gone
furthest beyond the block, and down the rows where it has gone as far both ways.

**Repeat what is there, in its order.** A block of several values fills by
repeating them in turn, so that the block and what it filled tile. Filling
backwards tiles too: the cell before the block takes the block's last value.

**Continue a series only when there is one way to continue it.** Numbers a
constant step apart go on by that step; so do dates a constant number of days
apart, and dates on the same day of months a constant number of months apart.
It takes at least two values to say there is a step. One value, a gap among the
values, steps that differ, text, a choice — each is repeated, not continued.

**Never guess.** Where the values could be continued in more than one way, they
are repeated. The first of two months running is a month after the last, and
thirty-one days after it: which was meant is not said, so neither is assumed.
Months are not counted from a day that not every month has. A fill that copied
when a series was wanted is seen at once and put right; a fill that invented
values is found later, if at all.

**Continue exactly.** After 0.1 and 0.2 comes 0.3, not a number a hair away from
it. A series that would run past the last value its kind can hold puts nothing
there.

**Show what would be filled before it is.** While a corner is dragged, outline
the cells the fill would reach. Letting go fills them; Escape, before letting
go, takes the drag back and changes nothing.

**Make a fill one change.** However many cells it reaches, a fill is undone by
one undo, and is told to the data's owner as one change.

**Leave what cannot be changed, and say so.** A read-only cell in the way of a
fill is left as it was, and so is a cell whose column cannot read the value
offered it. Say how many cells were filled and how many were left, and why.

**Fill from the first line by a command.** "Fill down" gives every row of the
selection its first row's values; "fill across", every column its first
column's. With one row selected, fill down takes the row above. A command
copies and does not continue: only a drag from two cells says there is a series.

## Conventions

| Intent                  | Pointer                           | Keyboard  | Touch |
| ----------------------- | --------------------------------- | --------- | ----- |
| Fill beside a block     | Drag the handle at its end corner | —         | —     |
| Fill down               | Menu                              | Command-D | Menu  |
| Fill across             | Menu                              | Command-R | Menu  |
| Take back a fill's drag | —                                 | Escape    | —     |

Command is ⌘ on Apple platforms and Ctrl elsewhere.

See also [Cell selection](https://ui.publictheta.com/foundations/grid-selection.md) and
[Undo and redo](https://ui.publictheta.com/foundations/history.md).

## Behaviour

Each statement is verified by a test in Chromium, Chromium (touch), Firefox, WebKit, WebKit (touch), unless it names the environments it applies to or is marked open.

### Where a fill goes

- A corner dragged below the block fills the rows down to it, as wide as the block.
- Dragged above, or to either side, it fills back to there, or along the columns.
- A fill runs along one axis: the one the place dragged to is furthest beyond the block in.
- Within the block there is nothing to fill.
- What is filled never takes in a cell of the block, and always reaches the place dragged to along its axis.

### Filling down and across

- A block of several rows is filled down from its first row; of several columns, across from its first.
- A block of one row is filled from the row above it, and of one column from the column before.
- The first row has no row above to be filled from, nor the first column one before.

### Filling a series

- A block's lines that hold values, from its start, fill the rest of it: down its rows, or along its one row.
- A block that starts empty, is full to its end, or is one cell, has no series to fill.

### What fills

- Values are repeated in their order, after the line and before it, so that the whole tiles.
- Numbers a constant step apart go on by that step, forwards and back.
- Decimal numbers go on exactly: after 0.1 and 0.2 comes 0.3.
- One number, numbers whose steps differ, and numbers with a gap among them are repeated: a fill does not guess.
- Numbers are not continued where the values are not numbers to be continued.
- Dates a constant number of days apart go on by as many days, across months and years.
- Three dates on the same day of months a constant step apart go on by months.
- Two dates a month apart are as many days apart too: which was meant is not said, and they are repeated.
- Months are not counted from a day that not every month has.
- A series that runs past the last date a date can write has nothing to put there.
- A series of numbers agrees with adding the step, however far and whichever way.

## Reference implementation

React: `npx shadcn@latest add https://ui.publictheta.com/r/fill.json`
