Under the activity bar I have a section that shows the current project folders.
Next to each file I have a checkbox to toggle its location between 2 folders.
When the toggled file is open in the editor, the user should not see it was moved.
How can I move it seamlessly, with no refresh?
I am using the code below but currently the editor is being refreshed (flickers) after moving the file.
const content = fs.readFileSync(oldPath, 'utf-8');
try {
fs.writeFileSync(newPath, content);
await vscode.workspace.fs.rename(vscode.Uri.file(oldPath), vscode.Uri.file(newPath), { overwrite: true });
I’ve also tried using the fs.link
function, but it opens another editor for the new file location.
user21919725 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
VSCode will not refresh a file if you have unsaved changes in that file. To move a file seamlessly without triggering a refresh, follow these steps:
Read the content of the file using fs.readFileSync(oldPath, ‘utf-8’).
Write the content to the new location using fs.writeFileSync(newPath, content).
Rename the file using vscode.workspace.fs.rename(vscode.Uri.file(oldPath), vscode.Uri.file(newPath), { overwrite: true })It preserves your edits until you explicitly save them.You mentioned trying fs.link, but it opens another editor for the new file location. Unfortunately, there’s no direct way to prevent the editor from refreshing when moving files.
Consider using the provided approach, which ensures seamless movement while preserving unsaved changes.
Mohammed Faizan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.