fix: Line-numbering in code blocks runs horizontal on Linux
closes #4901
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { flattenDeep } from "lodash";
|
||||
import { flattenDeep, padStart } from "lodash";
|
||||
import { Node } from "prosemirror-model";
|
||||
import { Plugin, PluginKey, Transaction } from "prosemirror-state";
|
||||
import { findBlockNodes } from "prosemirror-utils";
|
||||
@@ -99,19 +99,20 @@ function getDecorations({
|
||||
if (lineNumbers) {
|
||||
const lineCount =
|
||||
(block.node.textContent.match(/\n/g) || []).length + 1;
|
||||
const gutterWidth = String(lineCount).length;
|
||||
|
||||
const lineCountText = new Array(lineCount)
|
||||
.fill(0)
|
||||
.map((_, i) => i + 1)
|
||||
.join("\n");
|
||||
.map((_, i) => padStart(`${i + 1}`, gutterWidth, " "))
|
||||
.join(" ");
|
||||
|
||||
lineDecorations.push(
|
||||
Decoration.node(
|
||||
block.pos,
|
||||
block.pos + block.node.nodeSize,
|
||||
{
|
||||
"data-line-numbers": lineCountText,
|
||||
style: `--line-number-gutter-width: ${String(lineCount).length};`,
|
||||
"data-line-numbers": `${lineCountText} `,
|
||||
style: `--line-number-gutter-width: ${gutterWidth};`,
|
||||
},
|
||||
{
|
||||
key: `line-${lineCount}-gutter`,
|
||||
|
||||
Reference in New Issue
Block a user