Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#211 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
90/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
desktop, devtools

Hướng nghiên cứu

Đọc advanced_new_file/commands/copy_file_command.py và advanced_new_file/commands/move_file_command.py, so sánh các phương thức _try_prompt_if_dest_exists của chúng và luồng move_from_argument. Tái hiện hành vi sao chép khi tắt cảnh báo ghi đè và hành vi di chuyển khi tệp nguồn đang mở trong một tab. Hoàn thành khi việc sao chép tiếp tục trong trường hợp thông thường và Move At hoàn tất mà không có NameError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
833
Fork
96
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SublimeText/AdvancedNewFile

Tất cả issue của SublimeText/AdvancedNewFile

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.