Copy command silently no-ops; Move At crashes with NameError on open files
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 90/100
Research direction
Read advanced_new_file/commands/copy_file_command.py and advanced_new_file/commands/move_file_command.py, comparing their _try_prompt_if_dest_exists methods and the move_from_argument path. Reproduce the copy behavior with overwrite warnings off and the move behavior with the source open in a tab. Done when copying proceeds in the normal case and Move At completes without a NameError.
Written by the indexing model from the issue text.
Description
Bug 1: AdvancedNewFileCopyCommand silently does nothing
_try_prompt_if_dest_exists in advanced_new_file/commands/copy_file_command.py has no fallback return:
def _try_prompt_if_dest_exists(self, target):
if self.settings.get(WARN_OVERWRITE_ON_COPY_SETTING, False):
if os.path.exists(target):
return sublime.ok_cancel_dialog(
target + " already exists. Copy will overwrite existing file. Continue?"
)
It implicitly returns None whenever warn_overwrite_on_copy is off (the default) or the target doesn't already exist — i.e. in almost every normal case. _copy_file then does:
if not self._try_prompt_if_dest_exists(path):
return (False, path)
Since not None is True, the copy is skipped unconditionally in that case. The visible symptom: the "Copy" input panel appears, you type a path, press enter, and nothing happens — no file is created, no error shown.
This has been present since the overwrite-warning feature was introduced in d4e1fc5 ("warn overwrite on copy command"). The sibling implementation in move_file_command.py's _try_prompt_if_dest_exists does this correctly (it has return True at the end) — copy_file_command.py's version is just missing that line.
Fix:
def _try_prompt_if_dest_exists(self, target):
if self.settings.get(WARN_OVERWRITE_ON_COPY_SETTING, False):
if os.path.exists(target):
return sublime.ok_cancel_dialog(
target + " already exists. Copy will overwrite existing file. Continue?"
)
return True
Bug 2: AdvancedNewFileMoveCommand.move_from_argument references an undefined window
In advanced_new_file/commands/move_file_command.py:
def move_from_argument(self, source, target):
file_view = self._find_open_file(source)
if file_view is not None:
self.view.run_command("save")
window.focus_view(file_view)
window.run_command("close")
...
window is never assigned in this method (every other method in the file does window = self.window first). This path is hit via "Move At" (sidebar context menu → Move) when the targeted file is also currently open in a tab, and raises NameError: name 'window' is not defined.
Fix: use self.window instead of the bare window in both places.
Happy to open a PR with both one-line fixes if that's useful.
- Dominant language
- Python
- Stars
- 833
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SublimeText/AdvancedNewFile
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
SublimeText/AdvancedNewFile#196 · 1 reaction ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
SublimeText/AdvancedNewFile#195 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
SublimeText/AdvancedNewFile#193 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
SublimeText/AdvancedNewFile#183 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
SublimeText/AdvancedNewFile#180 ·
All issues in SublimeText/AdvancedNewFile
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mohitmishra786/readprism#322 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
API-key credentials accept a blank key: empty via the API, spaces-only via the builder's Add API key dialogPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Significant-Gravitas/AutoGPT#15727 ·
Maintainers usually reply within 1 day