Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Copy command silently no-ops; Move At crashes with NameError on open files

未关闭 适合新手
#211 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
90/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
desktop, devtools

调研方向

阅读 advanced_new_file/commands/copy_file_command.py 和 advanced_new_file/commands/move_file_command.py,比较它们的 _try_prompt_if_dest_exists 方法和 move_from_argument 路径。复现关闭覆盖警告时的复制行为,以及源文件在标签页中打开时的移动行为。复制在正常情况下能够继续,且 Move At 完成时没有 NameError,即为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
834
派生
96
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SublimeText/AdvancedNewFile 的其他 Issue

查看 SublimeText/AdvancedNewFile 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。