-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show toast for easy jumping to currently edited file
- Loading branch information
Showing
14 changed files
with
82 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function urlFromPath(filepath: string): string | null { | ||
const normalizedPath = filepath.replace(/\\/g, '/') | ||
|
||
const match = normalizedPath.match(/^(?:.*\/src\/)(?<path>.+?)\/(?<filename>.+)\.[^\/]+$/) | ||
if (!match?.groups) | ||
return null | ||
|
||
const { path, filename } = match.groups | ||
const baseFilename = filename.split('.').shift() | ||
const url = `/${path}/${baseFilename}` | ||
return url | ||
} | ||
|
||
if (import.meta.vitest) { | ||
describe(urlFromPath, () => { | ||
test('handles linux filepaths', () => { | ||
expect(urlFromPath('/dev/project/src/lib/components/Foo.svelte')) | ||
.toEqual('/lib/components/Foo') | ||
}) | ||
test('handles windows filepaths', () => { | ||
expect(urlFromPath('C:\\dev\\project\\src\\routes\\+layout.svelte')) | ||
.toEqual('/routes/+layout') | ||
}) | ||
test('handles named compositions (filenames with multiple dots)', () => { | ||
expect(urlFromPath('/dev/project/src/lib/components/Foo.some.composition')) | ||
.toEqual('/lib/components/Foo') | ||
}) | ||
test('return null if path does not match', () => { | ||
expect(urlFromPath('/dev/project/some.config.ts')) | ||
.toBeNull() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters