-
Notifications
You must be signed in to change notification settings - Fork 223
feat: open .html files in built-in browser pane #1427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shreyaspapi
wants to merge
4
commits into
generalaction:main
Choose a base branch
from
shreyaspapi:feat/open-html-in-browser-pane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a0ed64d
feat: open .html files in built-in browser pane
shreyaspapi 5043944
refactor: extract browser pane utils and add tests
shreyaspapi a845b8e
fix: handle Windows drive-letter paths in buildFileUrl
shreyaspapi fb4317c
fix(browser-pane): fix white flash on first open and allow file:// in…
shreyaspapi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,25 @@ | ||
| /** | ||
| * Returns true when the filename ends with .html or .htm (case-insensitive). | ||
| */ | ||
| export function isHtmlFile(name: string): boolean { | ||
| return /\.html?$/i.test(name); | ||
| } | ||
|
|
||
| /** | ||
| * Normalises a value entered into the browser-pane address bar. | ||
| * - Preserves `http://`, `https://`, and `file://` URLs as-is. | ||
| * - Prepends `http://` to everything else so bare hostnames work. | ||
| */ | ||
| export function normalizeAddressBarUrl(input: string): string { | ||
| const trimmed = input.trim(); | ||
| if (/^(?:https?|file):\/\//i.test(trimmed)) return trimmed; | ||
| return `http://${trimmed}`; | ||
| } | ||
|
|
||
| /** | ||
| * Builds a `file://` URL from a root path and a relative file path. | ||
| */ | ||
| export function buildFileUrl(rootPath: string, relativePath: string): string { | ||
| const joined = [rootPath, relativePath].filter(Boolean).join('/').replace(/\/+/g, '/'); | ||
| return `file://${joined}`; | ||
| } | ||
This file contains hidden or 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,84 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| isHtmlFile, | ||
| normalizeAddressBarUrl, | ||
| buildFileUrl, | ||
| } from '../../renderer/lib/browserPaneUtils'; | ||
|
|
||
| describe('isHtmlFile', () => { | ||
| it('returns true for .html files', () => { | ||
| expect(isHtmlFile('index.html')).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for .htm files', () => { | ||
| expect(isHtmlFile('report.htm')).toBe(true); | ||
| }); | ||
|
|
||
| it('is case-insensitive', () => { | ||
| expect(isHtmlFile('Page.HTML')).toBe(true); | ||
| expect(isHtmlFile('doc.HTM')).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for non-HTML files', () => { | ||
| expect(isHtmlFile('script.js')).toBe(false); | ||
| expect(isHtmlFile('style.css')).toBe(false); | ||
| expect(isHtmlFile('data.json')).toBe(false); | ||
| expect(isHtmlFile('README.md')).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for filenames containing html but not ending with it', () => { | ||
| expect(isHtmlFile('html-parser.js')).toBe(false); | ||
| expect(isHtmlFile('my.html.bak')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('normalizeAddressBarUrl', () => { | ||
| it('preserves http:// URLs', () => { | ||
| expect(normalizeAddressBarUrl('http://localhost:3000')).toBe('http://localhost:3000'); | ||
| }); | ||
|
|
||
| it('preserves https:// URLs', () => { | ||
| expect(normalizeAddressBarUrl('https://example.com')).toBe('https://example.com'); | ||
| }); | ||
|
|
||
| it('preserves file:// URLs', () => { | ||
| expect(normalizeAddressBarUrl('file:///Users/test/index.html')).toBe( | ||
| 'file:///Users/test/index.html' | ||
| ); | ||
| }); | ||
|
|
||
| it('prepends http:// to bare hostnames', () => { | ||
| expect(normalizeAddressBarUrl('localhost:3000')).toBe('http://localhost:3000'); | ||
| }); | ||
|
|
||
| it('prepends http:// to bare domain names', () => { | ||
| expect(normalizeAddressBarUrl('example.com')).toBe('http://example.com'); | ||
| }); | ||
|
|
||
| it('trims whitespace', () => { | ||
| expect(normalizeAddressBarUrl(' https://example.com ')).toBe('https://example.com'); | ||
| }); | ||
|
|
||
| it('is case-insensitive for protocol detection', () => { | ||
| expect(normalizeAddressBarUrl('HTTP://example.com')).toBe('HTTP://example.com'); | ||
| expect(normalizeAddressBarUrl('FILE:///tmp/test.html')).toBe('FILE:///tmp/test.html'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildFileUrl', () => { | ||
| it('builds a file:// URL from root and relative path', () => { | ||
| expect(buildFileUrl('/Users/test/project', 'src/index.html')).toBe( | ||
| 'file:///Users/test/project/src/index.html' | ||
| ); | ||
| }); | ||
|
|
||
| it('collapses duplicate slashes', () => { | ||
| expect(buildFileUrl('/Users/test/project/', '/src/index.html')).toBe( | ||
| 'file:///Users/test/project/src/index.html' | ||
| ); | ||
| }); | ||
|
|
||
| it('handles root path only', () => { | ||
| expect(buildFileUrl('/Users/test/index.html', '')).toBe('file:///Users/test/index.html'); | ||
| }); | ||
| }); | ||
shreyaspapi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.