[PR #594] feat(core): show parent function/class context in diff hunk headers #1423

Open
opened 2026-03-14 09:36:02 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/594
Author: @remorses
Created: 1/27/2026
Status: 🔄 Open

Base: mainHead: contextual-lines


📝 Commits (10+)

  • a30bee0 contextual lines
  • eb111a2 change @@ positions
  • 4884fff use only one @
  • a71ecd4 use context bg for hunk header rows, add contextual diff demo example
  • e82c433 remove slop comments
  • c5d82d0 fix contextual diff example with realistic function/method scopes
  • 535a725 fix hunk line count in contextual diff example
  • b05d420 trimEnd inline snapshots
  • 0ef8c98 Merge remote-tracking branch 'upstream/main' into contextual-lines
  • 6996765 Merge remote-tracking branch 'upstream/main' into contextual-lines

📊 Changes

4 files changed (+345 additions, -21 deletions)

View changed files

📝 packages/core/src/examples/diff-demo.ts (+52 -12)
📝 packages/core/src/renderables/Diff.regression.test.ts (+2 -4)
📝 packages/core/src/renderables/Diff.test.ts (+190 -0)
📝 packages/core/src/renderables/Diff.ts (+101 -5)

📄 Description

Parses the context text after @@ in unified diff hunk headers (e.g. @@ -10,5 +10,7 @@ function setup()) and renders it as a separator row between hunks. The @ sign appears in the gutter column alongside +/-, and the function/class name appears in the content area with the same background as context lines.

  • Parse @@ context text from raw diff string and attach to each hunk
  • Render hunk header rows only when context text is present (no empty @@ rows)
  • Show @ in the gutter sign column, context text in content area
  • Use same background colors as context lines for seamless blending
  • Add hunkHeaderFg option for the @ sign color
  • Add diff demo example with contextual headers
  • Add tests with inline snapshots for unified and split views

Closes #587

Screenshot 2026-01-27 at 13 16 49 Screenshot 2026-01-27 at 13 17 10

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/594 **Author:** [@remorses](https://github.com/remorses) **Created:** 1/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `contextual-lines` --- ### 📝 Commits (10+) - [`a30bee0`](https://github.com/anomalyco/opentui/commit/a30bee0bfc9d46fd8740f521d0b3f07a884cfb0e) contextual lines - [`eb111a2`](https://github.com/anomalyco/opentui/commit/eb111a220cec4afbf0892e6a34cd9822a11c75e2) change @@ positions - [`4884fff`](https://github.com/anomalyco/opentui/commit/4884fff69f57b620977922c16152195b67a95fd8) use only one @ - [`a71ecd4`](https://github.com/anomalyco/opentui/commit/a71ecd403400df834ab117d9f1b1d1d748b2b354) use context bg for hunk header rows, add contextual diff demo example - [`e82c433`](https://github.com/anomalyco/opentui/commit/e82c4337b371ad0d7d44771edf79af6b55b34c92) remove slop comments - [`c5d82d0`](https://github.com/anomalyco/opentui/commit/c5d82d02212b4f9b09acd491f8d00dd86d8839e1) fix contextual diff example with realistic function/method scopes - [`535a725`](https://github.com/anomalyco/opentui/commit/535a725797b22aca89bace18ae235227da78e4ee) fix hunk line count in contextual diff example - [`b05d420`](https://github.com/anomalyco/opentui/commit/b05d420f0b3d020f8ead04146396bb73ac6b9481) trimEnd inline snapshots - [`0ef8c98`](https://github.com/anomalyco/opentui/commit/0ef8c9870319afb4d95fdddb43e6c31d1c1d041c) Merge remote-tracking branch 'upstream/main' into contextual-lines - [`6996765`](https://github.com/anomalyco/opentui/commit/69967656f170159ae1d91349a9967410d37fb9a4) Merge remote-tracking branch 'upstream/main' into contextual-lines ### 📊 Changes **4 files changed** (+345 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/examples/diff-demo.ts` (+52 -12) 📝 `packages/core/src/renderables/Diff.regression.test.ts` (+2 -4) 📝 `packages/core/src/renderables/Diff.test.ts` (+190 -0) 📝 `packages/core/src/renderables/Diff.ts` (+101 -5) </details> ### 📄 Description Parses the context text after `@@` in unified diff hunk headers (e.g. `@@ -10,5 +10,7 @@ function setup()`) and renders it as a separator row between hunks. The `@` sign appears in the gutter column alongside `+`/`-`, and the function/class name appears in the content area with the same background as context lines. - Parse `@@` context text from raw diff string and attach to each hunk - Render hunk header rows only when context text is present (no empty `@@` rows) - Show `@` in the gutter sign column, context text in content area - Use same background colors as context lines for seamless blending - Add `hunkHeaderFg` option for the `@` sign color - Add diff demo example with contextual headers - Add tests with inline snapshots for unified and split views Closes #587 <img width="1111" height="599" alt="Screenshot 2026-01-27 at 13 16 49" src="https://github.com/user-attachments/assets/f53b6df6-83e9-4f54-baa3-b7836297a6d7" /> <img width="1279" height="581" alt="Screenshot 2026-01-27 at 13 17 10" src="https://github.com/user-attachments/assets/da5658f5-a579-49fe-b436-d7715840c82a" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#1423
No description provided.