@@ -1452,14 +1452,24 @@ class ScriptEditorTab
1452
1452
this .totalChars ++ ;
1453
1453
}
1454
1454
1455
+ this .matchCollectedFoldingRegionsWithExisting(collectedRegions);
1456
+ }
1457
+
1458
+ private void mergeCollectedFoldingRegionsWithExisting(dictionary & in collectedRegions) // helper for `analyzeBuffer()`
1459
+ {
1460
+ // The `ImGui::TextInputMultiline()` doesn't provide info on where new characters were inserted/removed (or does it? TODO research ImGuiInputTextCallbackData)
1461
+ // Either way, we simply scan the buffer again, collect the regions and then match them with those already existing.
1462
+ // This relies on the #region/#endregion tags always being in the buffer, even if folded.
1463
+ // ---------------------------------------------------------------------------------------------------------------
1464
+
1455
1465
// prune broken regions (missing '#endregion' -> RegionInfo is null)
1456
1466
array < string > @ collectedRegionNames = collectedRegions.getKeys();
1457
1467
for (uint i = 0 ; i< collectedRegionNames.length(); i++ )
1458
1468
{
1459
1469
RegionInfo @ regionInfo = findRegion(collectedRegions, collectedRegionNames[i]);
1460
1470
if (@ regionInfo == null )
1461
1471
{
1462
- game.log (" DBG pruning broken region '" + collectedRegionNames[i] + " '" );
1472
+ // game.log ("DBG mergeCollectedFoldingRegionsWithExisting(): pruning broken region '" + collectedRegionNames[i] + "'");
1463
1473
collectedRegions.delete(collectedRegionNames[i]);
1464
1474
}
1465
1475
}
@@ -1472,7 +1482,7 @@ class ScriptEditorTab
1472
1482
RegionInfo @ oldRegionInfo = findRegion(this .workBufferRegions , oldRegionNames[i]);
1473
1483
if (isGone && oldRegionInfo.isFolded )
1474
1484
{
1475
- // game.log ("DBG analyzeBuffer (): region '" + oldRegionNames[i] + "' has gone orphan.");
1485
+ // game.log ("DBG mergeCollectedFoldingRegionsWithExisting (): region '" + oldRegionNames[i] + "' has gone orphan.");
1476
1486
oldRegionInfo.isOrphan = true ;
1477
1487
}
1478
1488
}
@@ -1482,32 +1492,34 @@ class ScriptEditorTab
1482
1492
for (uint i = 0 ; i < newRegionNames.length(); i++ )
1483
1493
{
1484
1494
RegionInfo @ newRegionInfo = findRegion(collectedRegions, newRegionNames[i]);
1485
- RegionInfo @ oldRegionInfo = findRegion(this .workBufferRegions , newRegionNames[i]);
1486
- if (@ oldRegionInfo == null )
1495
+ RegionInfo @ existingRegionInfo = findRegion(this .workBufferRegions , newRegionNames[i]);
1496
+ if (@ existingRegionInfo == null )
1487
1497
{
1488
- // game.log("DBG analyzeBuffer (): A brand new region '"+newRegionNames[i]+"' was created");
1498
+ // game.log("DBG mergeCollectedFoldingRegionsWithExisting (): A brand new region '"+newRegionNames[i]+"' was created");
1489
1499
this .workBufferRegions [newRegionNames[i]] = newRegionInfo;
1490
1500
}
1491
1501
else
1492
1502
{
1493
- /* game.log("DBG analyzeBuffer (): Region '"+newRegionNames[i]+"' already exists:"
1494
- +" lineCount="+oldRegionInfo .regionLineCount+" (new:"+newRegionInfo.regionLineCount+")"
1495
- +" regionBodyStartOffset="+oldRegionInfo .regionBodyStartOffset+" (new:"+newRegionInfo.regionBodyStartOffset+")"
1496
- +" regionBodyNumChars="+oldRegionInfo .regionBodyNumChars+" (new:"+newRegionInfo.regionBodyNumChars+")"
1497
- +" isOrphan="+oldRegionInfo .isOrphan+" isFolded="+newRegionInfo.isFolded);
1503
+ /* game.log("DBG mergeCollectedFoldingRegionsWithExisting (): Region '"+newRegionNames[i]+"' already exists:"
1504
+ +" lineCount="+existingRegionInfo .regionLineCount+" (new:"+newRegionInfo.regionLineCount+")"
1505
+ +" regionBodyStartOffset="+existingRegionInfo .regionBodyStartOffset+" (new:"+newRegionInfo.regionBodyStartOffset+")"
1506
+ +" regionBodyNumChars="+existingRegionInfo .regionBodyNumChars+" (new:"+newRegionInfo.regionBodyNumChars+")"
1507
+ +" isOrphan="+existingRegionInfo .isOrphan+" isFolded="+newRegionInfo.isFolded);
1498
1508
*/
1499
1509
1500
- if (oldRegionInfo.isOrphan && newRegionInfo.regionLineCount == 0 )
1510
+ existingRegionInfo.regionBodyStartOffset = newRegionInfo.regionBodyStartOffset ;
1511
+
1512
+ if (! existingRegionInfo.isFolded )
1501
1513
{
1502
- // game.log("DBG analyzeBuffer(): An orphan region '"+newRegionNames[i]+"' has resurfaced");
1503
- oldRegionInfo.regionBodyStartOffset = newRegionInfo.regionBodyStartOffset ;
1504
- oldRegionInfo.isOrphan = false ;
1514
+ // game.log("DBG mergeCollectedFoldingRegionsWithExisting(): An existing UNFOLDED region '"+newRegionNames[i]+"' was updated ~ text may have changed");
1515
+ existingRegionInfo.regionLineCount = newRegionInfo.regionLineCount ;
1516
+ existingRegionInfo.regionBodyNumChars = newRegionInfo.regionBodyNumChars ;
1517
+ existingRegionInfo.regionStartsAtLineIndex = newRegionInfo.regionStartsAtLineIndex ;
1505
1518
}
1506
- else if (! oldRegionInfo .isFolded )
1519
+ else if (existingRegionInfo .isOrphan && newRegionInfo .regionLineCount == 0 )
1507
1520
{
1508
- // game.log("DBG analyzeBuffer(): An existing region '"+newRegionNames[i]+"' was updated");
1509
- newRegionInfo.isFoldedBackup = oldRegionInfo.isFoldedBackup ; // don't lose backups!
1510
- this .workBufferRegions [newRegionNames[i]] = newRegionInfo;
1521
+ // game.log("DBG mergeCollectedFoldingRegionsWithExisting(): An orphan (so logically FOLDED) region '"+newRegionNames[i]+"' has resurfaced");
1522
+ existingRegionInfo.isOrphan = false ;
1511
1523
}
1512
1524
}
1513
1525
}
0 commit comments