Extract line number gutter width calculation and improve text selection
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Compute the pixel width for a line-number gutter based on the highest
|
||||||
|
* line number that will be displayed. Minimum width accommodates 2 digits.
|
||||||
|
*/
|
||||||
|
export function lineNumberGutterWidth(maxLineNumber: number): number {
|
||||||
|
const digits = Math.max(2, String(maxLineNumber).length);
|
||||||
|
return digits * 8 + 12;
|
||||||
|
}
|
||||||
|
|
||||||
export function getCodeInsets(theme: any) {
|
export function getCodeInsets(theme: any) {
|
||||||
const padding =
|
const padding =
|
||||||
typeof theme.spacing?.[3] === "number"
|
typeof theme.spacing?.[3] === "number"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import {
|
|||||||
type HighlightToken,
|
type HighlightToken,
|
||||||
type HighlightStyle,
|
type HighlightStyle,
|
||||||
} from "@getpaseo/highlight";
|
} from "@getpaseo/highlight";
|
||||||
|
import { lineNumberGutterWidth } from "@/components/code-insets";
|
||||||
|
|
||||||
interface CodeLineProps {
|
interface CodeLineProps {
|
||||||
tokens: HighlightToken[];
|
tokens: HighlightToken[];
|
||||||
@@ -100,6 +101,7 @@ const codeLineStyles = StyleSheet.create((theme) => ({
|
|||||||
fontSize: theme.fontSize.sm,
|
fontSize: theme.fontSize.sm,
|
||||||
lineHeight: theme.fontSize.sm * 1.45,
|
lineHeight: theme.fontSize.sm * 1.45,
|
||||||
opacity: 0.4,
|
opacity: 0.4,
|
||||||
|
userSelect: "none",
|
||||||
},
|
},
|
||||||
lineText: {
|
lineText: {
|
||||||
fontFamily: Fonts.mono,
|
fontFamily: Fonts.mono,
|
||||||
@@ -135,8 +137,7 @@ function FilePreviewBody({
|
|||||||
|
|
||||||
const gutterWidth = useMemo(() => {
|
const gutterWidth = useMemo(() => {
|
||||||
if (!highlightedLines) return 0;
|
if (!highlightedLines) return 0;
|
||||||
const digits = String(highlightedLines.length).length;
|
return lineNumberGutterWidth(highlightedLines.length);
|
||||||
return Math.max(digits * 8 + 12, 28);
|
|
||||||
}, [highlightedLines]);
|
}, [highlightedLines]);
|
||||||
|
|
||||||
const handlePreviewScroll = useCallback(
|
const handlePreviewScroll = useCallback(
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ import {
|
|||||||
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
||||||
import { GitHubIcon } from "@/components/icons/github-icon";
|
import { GitHubIcon } from "@/components/icons/github-icon";
|
||||||
import { buildGitActions, type GitActions } from "@/components/git-actions-policy";
|
import { buildGitActions, type GitActions } from "@/components/git-actions-policy";
|
||||||
|
import { lineNumberGutterWidth } from "@/components/code-insets";
|
||||||
import {
|
import {
|
||||||
WebDesktopScrollbarOverlay,
|
WebDesktopScrollbarOverlay,
|
||||||
useWebDesktopScrollbarMetrics,
|
useWebDesktopScrollbarMetrics,
|
||||||
@@ -325,8 +326,7 @@ function DiffFileBody({
|
|||||||
hunk.newStart + hunk.newCount,
|
hunk.newStart + hunk.newCount,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const digitCount = Math.max(1, String(maxLineNo).length);
|
const gutterWidth = lineNumberGutterWidth(maxLineNo);
|
||||||
const gutterWidth = digitCount * 8 + 12;
|
|
||||||
return file.hunks.map((hunk, hunkIndex) => {
|
return file.hunks.map((hunk, hunkIndex) => {
|
||||||
let oldLineNo = hunk.oldStart;
|
let oldLineNo = hunk.oldStart;
|
||||||
let newLineNo = hunk.newStart;
|
let newLineNo = hunk.newStart;
|
||||||
@@ -1427,6 +1427,7 @@ const styles = StyleSheet.create((theme) => ({
|
|||||||
fontSize: theme.fontSize.xs,
|
fontSize: theme.fontSize.xs,
|
||||||
fontFamily: Fonts.mono,
|
fontFamily: Fonts.mono,
|
||||||
color: theme.colors.foregroundMuted,
|
color: theme.colors.foregroundMuted,
|
||||||
|
userSelect: "none",
|
||||||
},
|
},
|
||||||
addLineNumberText: {
|
addLineNumberText: {
|
||||||
color: theme.colors.palette.green[400],
|
color: theme.colors.palette.green[400],
|
||||||
@@ -1441,6 +1442,7 @@ const styles = StyleSheet.create((theme) => ({
|
|||||||
fontSize: theme.fontSize.xs,
|
fontSize: theme.fontSize.xs,
|
||||||
fontFamily: Fonts.mono,
|
fontFamily: Fonts.mono,
|
||||||
color: theme.colors.foreground,
|
color: theme.colors.foreground,
|
||||||
|
userSelect: "text",
|
||||||
},
|
},
|
||||||
addLineContainer: {
|
addLineContainer: {
|
||||||
backgroundColor: "rgba(46, 160, 67, 0.15)", // GitHub green
|
backgroundColor: "rgba(46, 160, 67, 0.15)", // GitHub green
|
||||||
|
|||||||
Reference in New Issue
Block a user