fix(hashline-edit): tolerate >>> prefix and spaces around # in line refs
This commit is contained in:
parent
365d863e3a
commit
b8257dc59c
@ -74,6 +74,28 @@ describe("parseLineRef", () => {
|
||||
//#then
|
||||
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", () => {
|
||||
|
||||
@ -16,7 +16,13 @@ const MISMATCH_CONTEXT = 2
|
||||
const LINE_REF_EXTRACT_PATTERN = /([0-9]+#[ZPMQVRWSNKTXJBYH]{2})/
|
||||
|
||||
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)) {
|
||||
return trimmed
|
||||
}
|
||||
@ -26,7 +32,7 @@ function normalizeLineRef(ref: string): string {
|
||||
return extracted[1]
|
||||
}
|
||||
|
||||
return trimmed
|
||||
return originalTrimmed
|
||||
}
|
||||
|
||||
export function parseLineRef(ref: string): LineRef {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user