Skip to content

feat: add file renaming #63

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

Merged
merged 2 commits into from
Jun 14, 2023
Merged

feat: add file renaming #63

merged 2 commits into from
Jun 14, 2023

Conversation

skirtles-code
Copy link
Contributor

I've added support for renaming files. A tab can be double clicked to edit the name.

The first file cannot be renamed via the UI. This check is using i > 0, the same as the delete X. Arguably it would be better to check the mainFile in the store explicitly, but I tried to stay consistent with the existing logic for the X.

The renameFile logic in the store does support renaming the mainFile, even though that can't be achieved via the UI. It also protects against a couple of error cases that the UI prevents. I thought they might be useful to anyone trying to use renameFile directly, rather than going through the UI.

The files are ordered based on the iteration order of an object. This needed to be taken into account in the renaming logic, to avoid the renamed file jumping to the end.

The SFC filename is included in the compiled output, so it needs to be compiled when the name changes.

The template for FileSelector.vue hasn't changed as much as the diff might suggest. A lot of those lines haven't changed apart from the extra indentation caused by the addition of the <template> tag.

class="file"
:class="{ active: store.state.activeFile.filename === file }"
@click="store.setActive(file)"
@dblclick="i > 0 && editFileName(file)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us check it by adding a new property of File, like renamable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why that might be desirable, but what I've done here is consistent with deleting a file.

My reasoning is that it's already possible to rename a file by deleting it and re-adding it. It's painful for the user, but it is possible. The only restriction we currently place on that in the UI is preventing the first file from being deleted. So I've maintained the same restriction for renaming.

I think there is potential for providing various forms of permissions, to restrict what files can be added/removed/renamed, but currently we don't have anything like that and I can't think of a reason why it would be necessary to add it specifically for renaming when it isn't available for deleting.

@yyx990803 yyx990803 merged commit eb41c3a into vuejs:main Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants