@batchfy/codemirror-minimap 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/Overlay.d.ts.map +1 -1
- package/dist/geometry.d.ts +130 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +321 -166
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/Overlay.ts +151 -118
- package/src/geometry.ts +402 -0
- package/src/index.ts +39 -25
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A minimap for CodeMirror 6.
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/@batchfy/codemirror-minimap)
|
|
6
|
+
|
|
7
|
+
Published on npm as
|
|
8
|
+
[**@batchfy/codemirror-minimap**](https://www.npmjs.com/package/@batchfy/codemirror-minimap).
|
|
9
|
+
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
7
12
|
```
|
package/dist/Overlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Overlay.d.ts","sourceRoot":"","sources":["../src/Overlay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Overlay.d.ts","sourceRoot":"","sources":["../src/Overlay.ts"],"names":[],"mappings":"AAgWA,eAAO,MAAM,OAAO,yCAAuB,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { EditorView } from "@codemirror/view";
|
|
2
|
+
import { type Lines } from "./LinesState.js";
|
|
3
|
+
/** Editor pixels that fit into a single minimap pixel. */
|
|
4
|
+
export declare const SCALE: number;
|
|
5
|
+
export type LayoutInput = {
|
|
6
|
+
/** Rows the minimap draws: one per line it lays out, folds collapsed. */
|
|
7
|
+
rowCount: number;
|
|
8
|
+
/** Height of one row. */
|
|
9
|
+
lineHeight: number;
|
|
10
|
+
paddingTop: number;
|
|
11
|
+
paddingBottom: number;
|
|
12
|
+
/** Height of the visible minimap. */
|
|
13
|
+
height: number;
|
|
14
|
+
/** Rows the editor currently shows on screen, inclusive. */
|
|
15
|
+
firstVisibleRow: number;
|
|
16
|
+
lastVisibleRow: number;
|
|
17
|
+
/**
|
|
18
|
+
* Rows a screenful holds when none of its lines wrap.
|
|
19
|
+
*
|
|
20
|
+
* How many rows are on screen right now swings with how much the lines on
|
|
21
|
+
* it wrap: a screen of code holds many lines, a screen of prose few. This
|
|
22
|
+
* count follows from the editor's height and its line height alone, so it
|
|
23
|
+
* holds still while the document scrolls.
|
|
24
|
+
*/
|
|
25
|
+
rowsPerScreen: number;
|
|
26
|
+
};
|
|
27
|
+
export type Layout = {
|
|
28
|
+
/** Height of every row plus the document padding. */
|
|
29
|
+
contentHeight: number;
|
|
30
|
+
/** How far the rows are scrolled up inside the visible minimap. */
|
|
31
|
+
scrollTop: number;
|
|
32
|
+
/** Position of the viewport overlay inside the visible minimap. */
|
|
33
|
+
overlayTop: number;
|
|
34
|
+
overlayHeight: number;
|
|
35
|
+
/** Rows the minimap has to draw, carried through for the inverse. */
|
|
36
|
+
rowCount: number;
|
|
37
|
+
/**
|
|
38
|
+
* Rows the document can scroll through if none of its lines wrap: the ones
|
|
39
|
+
* past the first screenful.
|
|
40
|
+
*
|
|
41
|
+
* Wrapping puts fewer document lines on a screen than there are rows in it,
|
|
42
|
+
* so the editor can carry on past this — `rowAtOverlayTop` covers the rest.
|
|
43
|
+
*/
|
|
44
|
+
scrollableRows: number;
|
|
45
|
+
/**
|
|
46
|
+
* How far the overlay's top edge moves between the first row of the
|
|
47
|
+
* document and the last, and so how far a drag has to travel to cross the
|
|
48
|
+
* document. It is `overlayTravel / scrollableRows` per row, which is what
|
|
49
|
+
* `rowAtOverlayTop` inverts.
|
|
50
|
+
*/
|
|
51
|
+
overlayTravel: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Places the rows and the viewport overlay together.
|
|
55
|
+
*
|
|
56
|
+
* The overlay marks lines, not pixels, so its position cannot be derived from
|
|
57
|
+
* the editor's scroll offset: a wrapped line takes several rows of the editor
|
|
58
|
+
* and one row of the minimap, so equal scroll fractions stop meaning equal
|
|
59
|
+
* positions as soon as wrapping, folding or line-height variation enters the
|
|
60
|
+
* document. Both halves are therefore anchored on the rows that are actually on
|
|
61
|
+
* screen, which keeps the overlay on top of the content it stands for.
|
|
62
|
+
*
|
|
63
|
+
* The rows scroll in step with progress through the document, so the overlay
|
|
64
|
+
* ends up where that progress says it should: at the top on the first row, at
|
|
65
|
+
* the bottom on the last. Near either end, and whenever the rows have less to
|
|
66
|
+
* give than the progress asks for, the rows stop and the overlay takes over the
|
|
67
|
+
* remaining travel — covering its own rows always wins over sitting where the
|
|
68
|
+
* scroll fraction would like it to.
|
|
69
|
+
*/
|
|
70
|
+
export declare function computeLayout(input: LayoutInput): Layout;
|
|
71
|
+
export type Geometry = Layout & {
|
|
72
|
+
lineHeight: number;
|
|
73
|
+
paddingTop: number;
|
|
74
|
+
paddingBottom: number;
|
|
75
|
+
/** Height of the visible minimap. */
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The part of the geometry that scrolling does not change.
|
|
80
|
+
*
|
|
81
|
+
* Everything here follows from the document's length, the theme's row height
|
|
82
|
+
* and the size of the editor, so it holds still while the document moves under
|
|
83
|
+
* the overlay. A drag can therefore measure it once at the outset instead of on
|
|
84
|
+
* every report from the pointer — and the type is the argument that this is
|
|
85
|
+
* safe, since a function given only these values cannot read the scroll
|
|
86
|
+
* position it would be caching past.
|
|
87
|
+
*/
|
|
88
|
+
export type StableGeometry = Pick<Geometry, "paddingTop" | "lineHeight" | "rowCount" | "scrollableRows" | "overlayTravel">;
|
|
89
|
+
export declare function setRowHeight(view: EditorView, canvasLineHeight: number): void;
|
|
90
|
+
/** Index of the row the minimap draws the given document position on. */
|
|
91
|
+
export declare function rowAtPos(lines: Lines, pos: number): number;
|
|
92
|
+
/**
|
|
93
|
+
* Where the minimap draws its rows and its overlay for the current state.
|
|
94
|
+
*
|
|
95
|
+
* `token` stands for the moment being drawn: anything measured for the same
|
|
96
|
+
* token describes the same moment, so it is measured once. Callers with no
|
|
97
|
+
* moment to name pass nothing and get a fresh measurement.
|
|
98
|
+
*/
|
|
99
|
+
export declare function readGeometry(view: EditorView, token?: object): Geometry;
|
|
100
|
+
/** The row drawn `y` pixels below the top of the visible minimap. */
|
|
101
|
+
export declare function rowAtY(geometry: Geometry, y: number): number;
|
|
102
|
+
/**
|
|
103
|
+
* The row the editor would have to put at the top of its viewport for the
|
|
104
|
+
* overlay to sit at `overlayTop`.
|
|
105
|
+
*
|
|
106
|
+
* This is the inverse of the placement `computeLayout` performs, so dragging
|
|
107
|
+
* the overlay to a position and letting the layout put it back lands on the
|
|
108
|
+
* same pixel. It cannot be read off `rowAtY`: the rows underneath the overlay
|
|
109
|
+
* scroll as the overlay moves, so the row drawn at a position is not the row
|
|
110
|
+
* that would be on screen were the overlay taken there.
|
|
111
|
+
*
|
|
112
|
+
* The answer carries its fraction. A whole number of rows is not enough to
|
|
113
|
+
* reach the end of a document: the editor stops with the last line against the
|
|
114
|
+
* foot of the viewport, which in general falls part-way through a row, and a
|
|
115
|
+
* drag that could only name whole rows would stop short of it by that part and
|
|
116
|
+
* need a jump to finish.
|
|
117
|
+
*/
|
|
118
|
+
export declare function rowAtOverlayTop(geometry: StableGeometry, overlayTop: number): number;
|
|
119
|
+
/**
|
|
120
|
+
* Scrolls the editor until `row` sits `offset` pixels down the viewport.
|
|
121
|
+
*
|
|
122
|
+
* `row` may name a point inside a row rather than the start of one, and the
|
|
123
|
+
* fraction is taken against that row's own height so that it means the same
|
|
124
|
+
* part of a wrapped line as of an unwrapped one. Scrolling to whole rows is
|
|
125
|
+
* enough for a click, which is aiming at a line; a drag needs the fraction, or
|
|
126
|
+
* it cannot follow the pointer through the last part of a row and stops short
|
|
127
|
+
* of the end of the document.
|
|
128
|
+
*/
|
|
129
|
+
export declare function scrollToRow(view: EditorView, row: number, offset?: number): void;
|
|
130
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEzD,0DAA0D;AAC1D,eAAO,MAAM,KAAK,QAA0C,CAAC;AAK7D,MAAM,MAAM,WAAW,GAAG;IACtB,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,aAAa,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACjB,qDAAqD;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,aAAa,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAqDxD;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAC7B,QAAQ,EACN,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,gBAAgB,GAChB,eAAe,CACpB,CAAC;AAYF,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,QAOtE;AAED,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgB1D;AAuDD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,CAgBvE;AA0BD,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAO5D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,MAAM,GACnB,MAAM,CAoCR;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI,QAyBpE"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAU,OAAO,EAAS,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAU,OAAO,EAAS,MAAM,aAAa,CAAC;AA8VrD,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;IAC3D;;OAEG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK;QAAE,GAAG,EAAE,WAAW,CAAA;KAAE,CAAC;CACtD;AAED;;;;;GAKG;AACH,QAAA,MAAM,WAAW,mDAaf,CAAC;AAEH,OAAO,EAAE,WAAW,EAAE,CAAC"}
|