瀏覽代碼

Datafiles: fix watchers & deletion of separators

lviguier 1 年之前
父節點
當前提交
eedac615e5
共有 1 個文件被更改,包括 10 次插入5 次删除
  1. 10 5
      hide/comp/cdb/DataFiles.hx

+ 10 - 5
hide/comp/cdb/DataFiles.hx

@@ -306,7 +306,7 @@ class DataFiles {
 		}
 
 		// Find current separator corresponding to this path
-		var currentSepIdx = 0;
+		var currentSepIdx = -1;
 		for (sIdx => s in separators) {
 			if (s.path == path) {
 				currentSepIdx = sIdx;
@@ -314,6 +314,9 @@ class DataFiles {
 			}
 		}
 
+		if (currentSepIdx == -1)
+			return;
+
 		// Delete content of the separator we want to remove (lines, separator etc)
 		if (deleteWithContent) {
 			var currentSep = separators[currentSepIdx];
@@ -348,10 +351,9 @@ class DataFiles {
 			}
 
 			// Shift separators
-			var diff = (lineEnd + 1) - lineBegin;
-			for (sepIdx => s in separators) {
-				if (s != currentSep && sepIdx >= begin && sepIdx <= end)
-					s.index -= diff;
+			var diff = lineEnd - lineBegin;
+			for (sepIdx in (begin+1)...separators.length) {
+					separators[sepIdx].index -= diff;
 			}
 		}
 
@@ -403,6 +405,9 @@ class DataFiles {
 						// Meaning this is a deleted file
 						if (StringTools.contains(abs, fullPath) && abs != fullPath && !sys.FileSystem.exists(abs)) {
 							watching.remove(p);
+							var w = @:privateAccess Ide.inst.fileWatcher.getWatches(Ide.inst.getPath(p));
+							w.w?.close();
+							@:privateAccess Ide.inst.fileWatcher.watches.remove(p);
 
 							if (!sys.FileSystem.isDirectory(abs)) {
 								for( sheet in base.sheets ) {