Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToFileURL } from "url"
import path from "path"
import type { BoxRenderable, TextareaRenderable, KeyEvent, ScrollBoxRenderable } from "@opentui/core"
import fuzzysort from "fuzzysort"
import { firstBy } from "remeda"
Expand All @@ -14,8 +16,7 @@ import type { PromptInfo } from "./history"
import { useFrecency } from "./frecency"

function removeLineRange(input: string) {
const hashIndex = input.lastIndexOf("#")
return hashIndex !== -1 ? input.substring(0, hashIndex) : input
return extractLineRange(input).baseQuery
}

function extractLineRange(input: string) {
Expand All @@ -29,7 +30,7 @@ function extractLineRange(input: string) {
const lineMatch = linePart.match(/^(\d+)(?:-(\d*))?$/)

if (!lineMatch) {
return { baseQuery: baseName }
return { baseQuery: input }
}

const startLine = Number(lineMatch[1])
Expand Down Expand Up @@ -246,17 +247,16 @@ export function Autocomplete(props: {
const width = props.anchor().width - 4
options.push(
...sortedFiles.map((item): AutocompleteOption => {
let url = `file://${process.cwd()}/${item}`
const urlObj = pathToFileURL(path.resolve(process.cwd(), item))
let filename = item
if (lineRange && !item.endsWith("/")) {
filename = `${item}#${lineRange.startLine}${lineRange.endLine ? `-${lineRange.endLine}` : ""}`
const urlObj = new URL(url)
urlObj.searchParams.set("start", String(lineRange.startLine))
if (lineRange.endLine !== undefined) {
urlObj.searchParams.set("end", String(lineRange.endLine))
}
url = urlObj.toString()
}
const url = urlObj.toString()

const isDir = item.endsWith("/")
return {
Expand Down
Loading