Skip to content

Commit

Permalink
Datafiles: manage basic separators removale
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoVgr committed Apr 25, 2024
1 parent 0d7e6e6 commit af7deb6
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions hide/comp/cdb/DataFiles.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,25 @@ class DataFiles {
if (parent == null) {
for (rem in toRemove) {
var idxRemove = sheet.sheet.linesData.indexOf(rem);
sheet.sheet.linesData.remove(rem);
sheet.sheet.lines.remove(sheet.sheet.lines[idxRemove]);

var sepIdx = 0;
// Shift sperators
var sepIdx = sheet.sheet.separators.length;
for (idx => s in sheet.sheet.separators) {
if (s.index >= idxRemove) {
if (s.index > idxRemove) {
sepIdx = idx;
break;
}

}

// Shift sperators
for (idx in (sepIdx + 1)...sheet.sheet.separators.length)
for (idx in (sepIdx)...sheet.sheet.separators.length)
sheet.sheet.separators[idx].index--;

sheet.sheet.linesData.remove(rem);
sheet.sheet.lines.remove(sheet.sheet.lines[idxRemove]);

// Remove potentials un-used separators
removeSeparatorForPath(file, sheet);
}
}
}
Expand Down Expand Up @@ -257,6 +262,50 @@ class DataFiles {
return newSepIdx;
}

/*
Remove all non-used separators for this path
*/
static function removeSeparatorForPath(path: String, sheet: cdb.Sheet) {
var separators = @:privateAccess sheet.sheet.separators;
var lines = @:privateAccess sheet.sheet.lines;

function isSeparatorEmpty(sepIdx: Int) : Bool {
if (sepIdx == separators.length - 1)
return separators[sepIdx].index > lines.length - 1;

var next = null;

var idx = sepIdx + 1;
while (idx < separators.length) {
if (separators[idx].level <= separators[sepIdx].level) {
next = separators[idx];
break;
}

idx++;
}

if (next == null)
return separators[sepIdx].index > lines.length - 1;


return next.index <= separators[sepIdx].index;
}

var currentSepIdx = 0;

for (sIdx => s in separators) {
if (s.path == path) {
currentSepIdx = sIdx;
break;
}
}

var currentSep = separators[currentSepIdx];
if (isSeparatorEmpty(currentSepIdx))
separators.remove(currentSep);
}

#if (editor || cdb_datafiles)
static function onFileChanged(path: String) {
if( skip > 0 ) {
Expand Down

0 comments on commit af7deb6

Please sign in to comment.