@kitlangton/ghui 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitlangton/ghui",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Terminal UI for GitHub pull requests",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/App.tsx CHANGED
@@ -1024,7 +1024,7 @@ export const App = () => {
1024
1024
  setDetailScrollOffset(0)
1025
1025
  return
1026
1026
  }
1027
- if (key.name === "p" && selectedPullRequest) {
1027
+ if ((key.name === "d" || key.name === "p") && selectedPullRequest) {
1028
1028
  openDiffView()
1029
1029
  return
1030
1030
  }
@@ -1041,7 +1041,7 @@ export const App = () => {
1041
1041
  flashNotice(`Opened #${selectedPullRequest.number} in browser`)
1042
1042
  return
1043
1043
  }
1044
- if ((key.name === "d" || key.name === "D") && selectedPullRequest) {
1044
+ if ((key.name === "s" || key.name === "S") && selectedPullRequest) {
1045
1045
  const previousPullRequest = selectedPullRequest
1046
1046
  const nextReviewStatus = selectedPullRequest.reviewStatus === "draft" ? "review" : "draft"
1047
1047
  updatePullRequest(selectedPullRequest.url, (pullRequest) => ({
@@ -104,33 +104,16 @@ export const FooterHints = ({
104
104
  </>
105
105
  ) : null}
106
106
  <span fg={colors.count}>r</span>
107
- <span fg={colors.muted}>{hasError ? " retry " : " ref "}</span>
108
- {hasSelection ? (
109
- <>
110
- <span fg={colors.count}>↑↓</span>
111
- <span fg={colors.muted}> move </span>
112
- </>
113
- ) : null}
114
- {hasSelection && detailFullView ? (
115
- <>
116
- <span fg={colors.count}>esc</span>
117
- <span fg={colors.muted}> back </span>
118
- </>
119
- ) : hasSelection ? (
120
- <>
121
- <span fg={colors.count}>enter</span>
122
- <span fg={colors.muted}> expand </span>
123
- </>
124
- ) : null}
107
+ <span fg={colors.muted}>{hasError ? " retry " : " refresh "}</span>
125
108
  {hasSelection ? (
126
109
  <>
110
+ <span fg={colors.count}>s</span>
111
+ <span fg={colors.muted}> state </span>
127
112
  <span fg={colors.count}>d</span>
128
- <span fg={colors.muted}> draft </span>
129
- <span fg={colors.count}>p</span>
130
113
  <span fg={colors.muted}> diff </span>
131
114
  <span fg={colors.count}>l</span>
132
115
  <span fg={colors.muted}> labels </span>
133
- <span fg={colors.count}>M</span>
116
+ <span fg={colors.count}>m</span>
134
117
  <span fg={colors.muted}> merge </span>
135
118
  <span fg={colors.count}>o</span>
136
119
  <span fg={colors.muted}> open </span>
package/src/ui/diff.ts CHANGED
@@ -89,6 +89,41 @@ const patchFileName = (patch: string) => {
89
89
  return nextLine ? unquoteDiffPath(nextLine.slice(4).trim()) : "diff"
90
90
  }
91
91
 
92
+ const hunkHeaderPattern = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/
93
+
94
+ const formatHunkRange = (start: string, count: number) => `${start},${count}`
95
+
96
+ const normalizeHunkLineCounts = (patch: string) => {
97
+ const lines = patch.split("\n")
98
+ const normalized = [...lines]
99
+
100
+ for (let index = 0; index < lines.length; index++) {
101
+ const match = lines[index]!.match(hunkHeaderPattern)
102
+ if (!match) continue
103
+
104
+ let oldCount = 0
105
+ let newCount = 0
106
+ for (let lineIndex = index + 1; lineIndex < lines.length; lineIndex++) {
107
+ const line = lines[lineIndex]!
108
+ if (line.startsWith("@@ ") || line.startsWith("diff --git ")) break
109
+
110
+ const prefix = line[0]
111
+ if (prefix === " ") {
112
+ oldCount += 1
113
+ newCount += 1
114
+ } else if (prefix === "-") {
115
+ oldCount += 1
116
+ } else if (prefix === "+") {
117
+ newCount += 1
118
+ }
119
+ }
120
+
121
+ normalized[index] = `@@ -${formatHunkRange(match[1]!, oldCount)} +${formatHunkRange(match[3]!, newCount)} @@${match[5]!}`
122
+ }
123
+
124
+ return normalized.join("\n")
125
+ }
126
+
92
127
  export const splitPatchFiles = (patch: string): readonly DiffFilePatch[] => {
93
128
  const trimmed = patch.trimEnd()
94
129
  if (trimmed.length === 0) return []
@@ -101,7 +136,7 @@ export const splitPatchFiles = (patch: string): readonly DiffFilePatch[] => {
101
136
  return matches.map((match, index) => {
102
137
  const start = match.index ?? 0
103
138
  const end = index + 1 < matches.length ? matches[index + 1]!.index ?? trimmed.length : trimmed.length
104
- const filePatch = trimmed.slice(start, end).trimEnd()
139
+ const filePatch = normalizeHunkLineCounts(trimmed.slice(start, end).trimEnd())
105
140
  const name = patchFileName(filePatch)
106
141
  return { name, filetype: filetypeForPath(name), patch: filePatch }
107
142
  })