-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Do not select the extension when refactoring file names #3552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! I think to be on the safe side, we should indeed do some smarter refactoring to only not select the text after the dot if we know the command is referencing a file name, so something like this:
override fun createRenameDialog(project: Project, element: PsiElement, nameSuggestionContext: PsiElement?, editor: Editor?): RenameDialog {
return object : PsiFileRenameDialog(project, element, nameSuggestionContext, editor) {
override fun createNewNameComponent() {
super.createNewNameComponent()
// if psi element references a file name:
nameSuggestionsField.selectNameWithoutExtension()
}
}
}
override fun canProcessElement(element: PsiElement): Boolean {
return when (element) {
is PsiFile -> true
else -> true
}
} but it only runs on Files, and is only a rename refactorer, what other cases are there? |
I don't understand that code snippet, it's just |
Oops, dont know how i missed that. ofc the else should be false 😑 |
Ah okay, then yes if you set editor to null only if the psi element is a PsiFile, if that works then I can agree to that. |
I checked and it still works with the else branch being false. Ready to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I just added a comment to explain
Fix #3551
So. The simplest solution was to simply make a custom Rename Processor that would gobble up ALL PsiFiles and automatically null the editor. This has the side effect of making every file refactor not select the extension by default, which covers my issue, but may cause problems?
I tested, every
\input
will have this behavior (which IMO is just another manifestation of this issue), refactoring commands from\newcommand
is unaffected.Attempting to refactor a package does not work.
Let me know if we need to go ahead and actually implement more logic. If anything, this opens the door to smarter refactoring?
\includegraphics{IM<caret>G.jpg}