Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: scroll position in code blocks

Alaister Young352acadc926d
diff --git a/www/components/ScrollableCodeBlock.tsx b/www/components/ScrollableCodeBlock.tsx
index 8c4c67b26f8..400d9931e61 100644
--- a/www/components/ScrollableCodeBlock.tsx
+++ b/www/components/ScrollableCodeBlock.tsx
@@ -9,7 +9,7 @@ interface ScrollableCodeBlockProps extends CodeBlockProps {
const MAX_HEIGHT = 520
const CODE_LINE_HEIGHT = 22
-const TOP_OFFSET = 10
+const TOP_OFFSET = 30
const ScrollableCodeBlock = ({
highlightLines: highlightLinesRange,
@@ -23,20 +23,17 @@ const ScrollableCodeBlock = ({
const firstLine = Math.min(...highlightLines)
const lastLine = Math.max(...highlightLines)
- // const firstLinePosition = Math.max(firstLine * CODE_LINE_HEIGHT - MAX_HEIGHT / 2 + TOP_OFFSET, 0)
const firstLinePosition = firstLine * CODE_LINE_HEIGHT
- console.log('firstLinePosition:', firstLinePosition)
const lastLinePosition = lastLine * CODE_LINE_HEIGHT
- console.log('lastLinePosition:', lastLinePosition)
const middlePosition = (firstLinePosition + lastLinePosition) / 2
- console.log('middlePosition:', middlePosition)
+ const position = Math.max(middlePosition - MAX_HEIGHT / 2 + TOP_OFFSET, 0)
return (
<div className="overflow-hidden" style={{ maxHeight: MAX_HEIGHT }}>
<div
className="transition-transform duration-500"
- style={{ transform: `translate3d(0, -${middlePosition}px, 0)` }}
+ style={{ transform: `translate3d(0, -${position}px, 0)` }}
>
<CodeBlock highlightLines={highlightLinesRange} {...props}>
{children + '\n'.repeat(100)}
diff --git a/www/pages/edge-functions/edge-functions.tsx b/www/pages/edge-functions/edge-functions.tsx
index 54ac4b3c3b3..8fb6637e3f8 100644
--- a/www/pages/edge-functions/edge-functions.tsx
+++ b/www/pages/edge-functions/edge-functions.tsx
@@ -85,7 +85,7 @@ function Database() {
const meta_title = `${title}`
const meta_description = subtitle
- const highlightLines = ['1..8', '11..24', '28', '31']
+ const highlightLines = ['1..8', '11..23', '28', '31']
const [currentSelection, setCurrentSelection] = useState(highlightLines[0])