# line-top-index

> A data structure to efficiently represent the top position of lines in the presence of fixed-height blocks.

Latest version **0.3.1** (published 2017-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install line-top-index
pnpm add line-top-index
yarn add line-top-index
bun add line-top-index
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2017-05-10 |
| First published | 2015-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Nathan Sobo |
| Maintainers | as-cii, atom, maxbrunsfeld, nathansobo |
| Keywords | atom lines data-structure |

## Links

- npm: https://www.npmjs.com/package/line-top-index
- Repository: https://github.com/atom/line-top-index
- Issues: https://github.com/atom/line-top-index/issues
- npm.io page: https://npm.io/package/line-top-index

## Dependencies (1)

- [random-seed](https://npm.io/package/random-seed.md) ^0.2.0

## Recent versions

- 0.3.1 (latest) — 2017-05-10
- 0.3.0 — 2017-04-06
- 0.2.0 — 2016-01-13
- 0.1.1 — 2015-12-19
- 0.1.0 — 2015-12-18
- 0.0.1 — 2015-12-18

## README

# line-top-index

This is a module used by Atom to keep track of block decorations and to efficiently compute spatial conversions from pixels to rows and viceversa.

## Example

```js
let lineTopIndex = new LineTopIndex({defaultLineHeight: 42})
lineTopIndex.insertBlock(1, 0, 100, true)
lineTopIndex.insertBlock(2, 3, 100, false)

lineTopIndex.splice(2, 1, 3)

lineTopIndex.pixelPositionBeforeBlocksForRow(0) // => 0
lineTopIndex.pixelPositionAfterBlocksForRow(0) // => 100
lineTopIndex.rowForPixelPosition(30) // => 1
```

## API

### `insertBlock(id, row, height, isAfter)`

Inserts a block with the given `id` and `height` into the specified `row`. `isAfter` determines whether the block should be placed before or after the row.

### `resizeBlock(id, newHeight)`

Resizes the block corresponding to the given `id` with the specified `newHeight`.

### `moveBlock(id, newRow)`

Moves the block corresponding to the given `id` to `newRow`.

### `deleteBlock(id)`

Deletes the block corresponding to the given `id`.

### `setDefaultLineHeight(lineHeight)`

Changes the default line height to `lineHeight`.

### `splice(start, oldExtent, newExtent)`

Update the locations of all the blocks based on the description of a change to the text. The range of the replaced text is described by traversing from start by oldExtent. The range of the new text is described by traversing from start to newExtent. All the positions are expressed in terms of rows.

This method returns a `Set` that describes which block decorations were touched during the splice operation.

### `pixelPositionBeforeBlocksForRow(row)`

Returns the pixel position of the passed `row`, taking into account the height of block decorations before it but excluding the ones that immediately precede it.

### `pixelPositionAfterBlocksForRow(row)`

Returns the pixel position of the passed `row`, taking into account the height of block decorations before it and including the ones that immediately precede it.

### `rowForPixelPosition(pixels)`

Returns the row corresponding to the passed `pixels`. If the given pixel position lies inside a block, the corresponding row for that block will be returned.

---
_Source: https://npm.io/package/line-top-index · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
