Skip to content
Merged
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
51 changes: 27 additions & 24 deletions packages/mdx/src/smooth-code/use-dimensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,43 @@ function useDimensions(
code.next,
focus.next
)

const lines = (code.prev || code.next!)
.trimEnd()
.split(newlineRe)

const lineCount = lines.length

// avod setting the ref more than once https://github.com/code-hike/codehike/issues/232
let prevLineRefSet = false
const element = (
<code className="ch-code-scroll-parent">
<br />
{lines.map((line, i) => (
<div
ref={
line === prevLongestLine
? prevLineRef
: undefined
}
key={i}
>
{lineNumbers ? (
<span className="ch-code-line-number">
_{lineCount}
</span>
) : undefined}
<div
style={{
display: "inline-block",
// leftPad
marginLeft: 16,
}}
>
<span>{line}</span>
{lines.map((line, i) => {
const ref =
!prevLineRefSet && line === prevLongestLine
? prevLineRef
: undefined
prevLineRefSet = prevLineRefSet || ref != null
return (
<div ref={ref} key={i}>
{lineNumbers ? (
<span className="ch-code-line-number">
_{lineCount}
</span>
) : undefined}
<div
style={{
display: "inline-block",
// leftPad
marginLeft: 16,
}}
>
<span>{line}</span>
</div>
</div>
</div>
))}
)
})}
<br />
</code>
)
Expand Down