Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line numbers #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,32 @@ function getLineHeight(line, i, { styles }) {
return styles[i].height != null ? styles[i].height : 15;
}

function getLine(line, i, { styles }) {
function getLine(line, lineNumber, i, { styles }) {
const style = styles[i];
return (
<div
style={Object.assign({ overflow: "hidden", height: "15px" }, style)}
key={line.key}
>
<span
style={{
minWidth: "40px",
paddingLeft: "15px",
paddingRight: "15px",
textAlign: "right",
display: "inline-block",
opacity: 0.4,
WebkitTouchCallout: "none",
WebkitUserSelect: "none",
KhtmlUserSelect: "none",
MozUserSelect: "none",
OUserSelect: "none",
msUserSelect: "none",
userSelect: "none"
}}
>
{lineNumber}
</span>
{!line.tokens.length && <br />}
{line.tokens.map((token, i) => {
const style = themeStylesByType[token.type] || {};
Expand Down
7 changes: 6 additions & 1 deletion src/use-virtual-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function useChildren({
let bottomPlaceholderH = 0;

// This is the bottleneck
let visibleItemNumber = 1;
items.forEach((item, i) => {
const itemH = getRowHeight(item, i, data);
const nextH = h + itemH;
Expand All @@ -31,9 +32,13 @@ export default function useChildren({
} else if (isUnderBottom) {
bottomPlaceholderH += itemH;
} else {
children.push(getRow(item, i, data));
children.push(getRow(item, visibleItemNumber, i, data));
}

// if the middle property is true, the item(line) is shown
// and the related counter has to be increased by one
if (item.middle) visibleItemNumber++;

h = nextH;
});

Expand Down