mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-17 23:05:21 +00:00
20 lines
507 B
TypeScript
20 lines
507 B
TypeScript
|
|
import { Compartment } from "@codemirror/state";
|
||
|
|
import { lineNumbers } from "@codemirror/view";
|
||
|
|
|
||
|
|
const gutter = new Compartment();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Offsets the line numbers by the given amount
|
||
|
|
* @see: https://discuss.codemirror.net/t/codemirror-6-offset-line-numbers/2675/8
|
||
|
|
*/
|
||
|
|
export const lineOffsetExtension = (lineOffset: number) => {
|
||
|
|
const lines = lineNumbers({
|
||
|
|
formatNumber: (n) => {
|
||
|
|
return (n + lineOffset).toString();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
return [
|
||
|
|
gutter.of(lines)
|
||
|
|
]
|
||
|
|
}
|