summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components/diff/diff.go
diff options
context:
space:
mode:
authorMatias Insaurralde <[email protected]>2025-07-16 06:20:25 -0300
committerGitHub <[email protected]>2025-07-16 04:20:25 -0500
commite89972a396c5b71b27b54c841fe26a2e9e53f5be (patch)
tree8883b42c17c79f77b699d372394df5fcbf951369 /packages/tui/internal/components/diff/diff.go
parentc3c647a21a4a04cb80dd90cbc0d78b180584e096 (diff)
downloadopencode-e89972a396c5b71b27b54c841fe26a2e9e53f5be.tar.gz
opencode-e89972a396c5b71b27b54c841fe26a2e9e53f5be.zip
perf: move ANSI regex compilations to package level (#1040)
Signed-off-by: Matías Insaurralde <[email protected]>
Diffstat (limited to 'packages/tui/internal/components/diff/diff.go')
-rw-r--r--packages/tui/internal/components/diff/diff.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/packages/tui/internal/components/diff/diff.go b/packages/tui/internal/components/diff/diff.go
index 03f58cc26..da2e007c2 100644
--- a/packages/tui/internal/components/diff/diff.go
+++ b/packages/tui/internal/components/diff/diff.go
@@ -38,6 +38,10 @@ const (
LineRemoved // Line removed from the old file
)
+var (
+ ansiRegex = regexp.MustCompile(`\x1b(?:[@-Z\\-_]|\[[0-9?]*(?:;[0-9?]*)*[@-~])`)
+)
+
// Segment represents a portion of a line for intra-line highlighting
type Segment struct {
Start int
@@ -548,7 +552,6 @@ func createStyles(t theme.Theme) (removedLineStyle, addedLineStyle, contextLineS
// applyHighlighting applies intra-line highlighting to a piece of text
func applyHighlighting(content string, segments []Segment, segmentType LineType, highlightBg compat.AdaptiveColor) string {
// Find all ANSI sequences in the content
- ansiRegex := regexp.MustCompile(`\x1b(?:[@-Z\\-_]|\[[0-9?]*(?:;[0-9?]*)*[@-~])`)
ansiMatches := ansiRegex.FindAllStringIndex(content, -1)
// Build a mapping of visible character positions to their actual indices