Open links and workspace paths from replies with a click
Links come from OpenTUI's markdown link detection (renderer.getLinkAt) and open with xdg-open or open; a path under the click that names a workspace file opens it in the editor pane. A drag still selects.
This commit is contained in:
1 parent
aa865e24eb
commit
c1a7376aa8
8 files changed
+206
-16
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { isWebUrl, pathAt } from "../src/model/links.ts";
|
||||
|
||||
const at = (text: string, word: string) => pathAt(text, text.indexOf(word));
|
||||
|
||||
describe("paths in text", () => {
|
||||
test("a click anywhere in a path finds the whole path", () => {
|
||||
const text = "I changed src/ui/App.tsx and test/app.test.tsx.";
|
||||
expect(at(text, "src")).toBe("src/ui/App.tsx");
|
||||
expect(at(text, "App")).toBe("src/ui/App.tsx");
|
||||
expect(at(text, "app.test")).toBe("test/app.test.tsx");
|
||||
});
|
||||
|
||||
test("line numbers and leading dots are path syntax", () => {
|
||||
expect(at("see ./bin.ts:12:4 for it", "bin")).toBe("./bin.ts");
|
||||
expect(at("in ../shared/x.ts, line 3", "shared")).toBe("../shared/x.ts");
|
||||
expect(at("open ~/notes.md now", "notes")).toBe("~/notes.md");
|
||||
expect(at("(README.md)", "README")).toBe("README.md");
|
||||
});
|
||||
|
||||
test("words, URLs and punctuation are not paths", () => {
|
||||
expect(at("the build is done", "build")).toBeNull();
|
||||
expect(at("see https://example.com/a.html", "example")).toBeNull();
|
||||
expect(at("see https://example.com/a.html", "https")).toBeNull();
|
||||
expect(at("a, b", ",")).toBeNull();
|
||||
expect(at("version 1.2", "1.2")).toBeNull();
|
||||
});
|
||||
|
||||
test("web links open in the browser; file: links and bare targets are files", () => {
|
||||
expect(isWebUrl("https://example.com")).toBe(true);
|
||||
expect(isWebUrl("mailto:me@example.com")).toBe(true);
|
||||
expect(isWebUrl("file:///tmp/a.ts")).toBe(false);
|
||||
expect(isWebUrl("src/ui/App.tsx")).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user