microsoft / vscode-livepreview

Hosts a local server in your workspace for you to preview your webpages.
http://aka.ms/live-preview
MIT License
389 stars 56 forks source link

fragment/anchor in Uri is ignored when preview loose file #660

Open quanzhuo opened 2 months ago

quanzhuo commented 2 months ago

when I call command livePreview.start.preview.atFile from my extension and pass a vscode.Uri which contains a fragment.

const htmlFile = 'file:///home/quan/test.html#section2';
const uri = vscode.Uri.parse(htmlFile);
vscode.commands.executeCommand('livePreview.start.preview.atFile', uri);

The html is previewed successfully. however,the fragment is ignored. the preview browser did not jump to section2 in test.html

quanzhuo commented 2 months ago

More information:

If the html file to be previewed is in a workspace folder which is not a loose file.

construct the file uri like this will jump to the fragment. But the uri is not a valid vscode.Uri actually.

const uri = vscode.Uri.file('D:\\workspace\\cmake\\test\\qtimeline.html#duration-prop');
 vscode.commands.executeCommand('livePreview.start.preview.atFile', uri);

construct the file uri like this (which is a valid vscode.Uri) not work:

const uri = vscode.Uri.file('D:\\workspace\\cmake\\test\\qtimeline.html').with({ fragment: 'duration-prop' });
vscode.commands.executeCommand('livePreview.start.preview.atFile', uri);