fix(hashline-edit): tolerate >>> prefix and spaces around # in line refs

This commit is contained in:
YeonGyu-Kim 2026-02-24 18:21:05 +09:00
parent 365d863e3a
commit b8257dc59c
2 changed files with 30 additions and 2 deletions

View File

@ -74,6 +74,28 @@ describe("parseLineRef", () => {
//#then //#then
expect(result).toEqual({ line: 42, hash: "VK" }) expect(result).toEqual({ line: 42, hash: "VK" })
}) })
it("accepts refs copied with >>> marker only", () => {
//#given
const ref = ">>> 42#VK"
//#when
const result = parseLineRef(ref)
//#then
expect(result).toEqual({ line: 42, hash: "VK" })
})
it("accepts refs with spaces around hash separator", () => {
//#given
const ref = "42 # VK"
//#when
const result = parseLineRef(ref)
//#then
expect(result).toEqual({ line: 42, hash: "VK" })
})
}) })
describe("validateLineRef", () => { describe("validateLineRef", () => {

View File

@ -16,7 +16,13 @@ const MISMATCH_CONTEXT = 2
const LINE_REF_EXTRACT_PATTERN = /([0-9]+#[ZPMQVRWSNKTXJBYH]{2})/ const LINE_REF_EXTRACT_PATTERN = /([0-9]+#[ZPMQVRWSNKTXJBYH]{2})/
function normalizeLineRef(ref: string): string { function normalizeLineRef(ref: string): string {
const trimmed = ref.trim() const originalTrimmed = ref.trim()
let trimmed = originalTrimmed
trimmed = trimmed.replace(/^(?:>>>|[+-])\s*/, "")
trimmed = trimmed.replace(/\s*#\s*/, "#")
trimmed = trimmed.replace(/\|.*$/, "")
trimmed = trimmed.trim()
if (HASHLINE_REF_PATTERN.test(trimmed)) { if (HASHLINE_REF_PATTERN.test(trimmed)) {
return trimmed return trimmed
} }
@ -26,7 +32,7 @@ function normalizeLineRef(ref: string): string {
return extracted[1] return extracted[1]
} }
return trimmed return originalTrimmed
} }
export function parseLineRef(ref: string): LineRef { export function parseLineRef(ref: string): LineRef {