编辑:这是我创建的问题的链接[https://youtrack.jetbrains.com/issue/WEB-21956 https://youtrack.jetbrains.com/issue/WEB-21956 ]
是否可以将 WebStorm 的重构范围限制为您发出重构的文件(默认情况下)?
在本例中,我正在编辑一个文件,并且我想重构(重命名)一个变量。然后,WebStorm 对整个项目中的所有文件进行搜索。我在网上搜索过这个,只能找到特定文件夹的范围限制。我希望我不会为每个文件创建范围。
P.S.我发现这个相关问题(https://stackoverflow.com/questions/33197566/pycharm-limit-refactor-renaming-to-current-file https://stackoverflow.com/questions/33197566/pycharm-limit-refactor-renaming-to-current-file)。虽然我无法对此发表评论,因为我还没有 50 名代表(可惜)。如果它不在 PyCharm 中,那么它很可能不在 WebStorm 中(它们共享代码),因此这更多的是双重检查。如果事实证明它确实不存在,我将添加一个功能请求的链接,我将发布到 WebStorm 问题。
从 WebStorm 2016.1.3 开始,似乎无法更改default的行为Rename Refactoring
。唯一可用的选项是在一个limited scope https://stackoverflow.com/a/37687689/3079302,在这种情况下,您可以启用或禁用就地模式(see docs https://www.jetbrains.com/help/webstorm/2016.1/rename-refactorings.html).
以下是两种可能的工作流程。我将使用 PC 键盘快捷键给出说明,但您也可以通过上下文菜单实现相同的目的。
查找和替换
- 将插入符号移至您要重命名的符号
- Select the word with Ctrl + W
- Open Replace dialog with Ctrl + R
- Hit Tab and type the new name
-
Alt + P to replace current occurrence or Alt + A to replace all occurrences
重命名重构工具
- Open Rename Refactoring tool with Shift + F6
- 输入新名称
- 调整过滤器
Search in comments and strings
并为Search for text occurrences
(默认开启)
- Preview the refactoring (Alt + P)
- The
Find Refactoring Preview
pane will show up (Alt + 3 to focus), listing all the occurrences found
- In this list, you can select in which files the refactoring will take place; for instance, you can exclude all files by pressing Delete in the parent group, and then pressing Insert only in the target file
In this (stupid) example I am renaming require
to require2
. Several occurrences are found. I excluded all of them by excluding the main group, then just included one file. I could have excluded the remaining groups as well, or selected all with Ctrl + A and then Delete to exclude.
See also
- 限制 Webstorm 中的重构范围 https://stackoverflow.com/questions/19404829/limit-refactoring-scope-in-webstorm
- 有没有办法告诉 IntelliJ IDEA 在搜索/替换或重构期间不要查看文件? https://stackoverflow.com/questions/5682451/is-there-any-way-to-tell-intellij-idea-not-to-look-at-files-during-a-search-repl
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)