Skip to content

Commit

Permalink
when renaming a directory, it would be good to retarget all open view…
Browse files Browse the repository at this point in the history
…s from that folder to new location

so we do not lose changes

The ST default rename_path command doesn't do this
VS Code does this
LSP will do this
  • Loading branch information
predragnikolic committed Jun 27, 2024
1 parent e0c9c82 commit a52b5c4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugin/rename_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ def rename_path(self, old_path: str, new_path: str) -> None:
new_dir = Path(new_path).parent
if not os.path.exists(new_dir):
os.makedirs(new_dir)
isdir = os.path.isdir(old_path)
os.rename(old_path, new_path)
if isdir:
for v in self.window.views():
file_name = v.file_name()
if not file_name:
continue
if file_name.startswith(old_path):
v.retarget(file_name.replace(old_path, new_path))
if os.path.isfile(new_path):
def restore_regions(v: sublime.View | None) -> None:
if not v:
Expand Down

0 comments on commit a52b5c4

Please sign in to comment.