Skip to content

Commit 43f8165

Browse files
committed
reuse the same view
1 parent eac2813 commit 43f8165

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

remote_subl.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
WRITE_TEMP_FILE_ERROR = "Failed to write to temp file! Error: {}"
1414
CONNECTION_LOST = "Connection to {} is lost."
1515
FILES = {}
16+
LOST_FILES = {}
1617
server = None
1718

1819

@@ -83,6 +84,12 @@ def get_temp_dir(self):
8384
f.host and f.host == self.host:
8485
return f.temp_dir
8586

87+
for vid, f in LOST_FILES.items():
88+
if f.env["real-path"] and f.env["real-path"] == self.env["real-path"] and \
89+
f.host and f.host == self.host:
90+
LOST_FILES.pop(vid)
91+
return f.temp_dir
92+
8693
# Create a secure temporary directory, both for privacy and to allow
8794
# multiple files with the same basename to be edited at once without
8895
# overwriting each other.
@@ -228,8 +235,11 @@ def on_close(self, view):
228235
base_name = view.settings().get('remote_subl.base_name')
229236
if base_name:
230237
host = view.settings().get('remote_subl.host', "remote server")
238+
vid = view.id()
239+
if vid in LOST_FILES:
240+
LOST_FILES.pop(vid)
231241
try:
232-
file = FILES.pop(view.id())
242+
file = FILES.pop(vid)
233243
file.close()
234244
say('Closed {} in {}.'.format(base_name, host))
235245
except Exception:
@@ -285,7 +295,7 @@ def cleanup(self, session):
285295
vid_to_pop.append(vid)
286296

287297
for vid in vid_to_pop:
288-
FILES.pop(vid)
298+
LOST_FILES[vid] = FILES.pop(vid)
289299
sublime.View(vid).run_command("remote_subl_update_status_bar")
290300

291301

0 commit comments

Comments
 (0)