Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Diff/diff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import difflib
import time
from pathlib import Path
from typing import Iterable, Iterator, List, Optional
from typing import Iterable, Iterator, List

import sublime
import sublime_plugin
Expand Down Expand Up @@ -71,7 +71,8 @@ def is_visible(self, files: List[str]) -> bool:
class DiffChangesCommand(sublime_plugin.TextCommand):
def run(self, edit: sublime.Edit) -> None:
fname = self.view.file_name()
if not fname or not Path(fname).exists():
fpath = Path(fname)
if not fname or not fpath.exists():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path(None) raises a TypeError and bool(Path('')) is True.

sublime.status_message("Unable to diff changes because the file does not exist")
return

Expand All @@ -84,11 +85,11 @@ def run(self, edit: sublime.Edit) -> None:
b = get_lines_for_view(self.view)
add_no_eol_warning_if_applicable(b)

adate = time.ctime(Path(fname).stat().st_mtime)
adate = time.ctime(fpath.stat().st_mtime)
bdate = time.ctime()

diff = difflib.unified_diff(a, b, fname, fname, adate, bdate, lineterm="")
name = f"Unsaved Changes: {Path(fname).name}"
name = f"Unsaved Changes: {fpath.name}"
show_diff_output(diff, self.view, self.view.window(), name, "unsaved_changes", "diff_changes_to_buffer")

def is_enabled(self) -> bool:
Expand All @@ -97,7 +98,7 @@ def is_enabled(self) -> bool:

def show_diff_output(
diff: Iterable[str],
view: Optional[sublime.View],
view: sublime.View | None,
win: sublime.Window,
name: str,
panel_name: str,
Expand Down