Просмотр исходного кода

delete empty item before record undo

melon.yin 2 лет назад
Родитель
Сommit
2a6b64f7a1
3 измененных файлов с 69 добавлено и 8 удалено
  1. 33 7
      lib/process/workspace/recorder.dart
  2. 1 1
      lib/view/player/controller.dart
  3. 35 0
      pubspec.lock

+ 33 - 7
lib/process/workspace/recorder.dart

@@ -39,7 +39,11 @@ class MeasureRecorder implements IMeasureRecorder {
   /// 撤销一次操作
   bool undoOnce() {
     _finishLast();
-    return _undoOnce();
+    _cleanMeasureList();
+
+    final result = _undoOnce();
+    _checkReactive();
+    return result;
   }
 
   /// 清除所有记录
@@ -47,11 +51,13 @@ class MeasureRecorder implements IMeasureRecorder {
     if (_records.isEmpty) return;
 
     _finishLast();
+    _cleanMeasureList();
 
     final len = _records.length;
     for (var i = 0; i < len; i++) {
       _undoOnce();
     }
+    _checkReactive();
     _resetId();
   }
 
@@ -76,11 +82,11 @@ class MeasureRecorder implements IMeasureRecorder {
   }
 
   bool _undoOnceMeasure(_MeasureModel record) {
-    final matchs =
-        _application.measureItems.where((e) => e.meta.name == record.name);
-    if (matchs.isEmpty) return false;
+    final index = _application.measureItems
+        .lastIndexWhere((e) => e.meta.name == record.name);
+    if (index < 0) return false;
 
-    final item = matchs.last;
+    final item = _application.measureItems[index];
     if (item is ITopMeasureItem) {
       _application.measureItems.remove(item);
     } else {
@@ -90,15 +96,35 @@ class MeasureRecorder implements IMeasureRecorder {
         item.measuredFeatures.removeLast();
       }
       if (item.measuredFeatures.isEmpty) {
-        _application.measureItems.remove(item);
+        _application.measureItems.removeAt(index);
       }
     }
+    return true;
+  }
+
+  void _checkReactive() {
     if (_application.measureItems.isEmpty) {
       if (_application.activeMeasureItem != null) {
         _application.switchItem(_application.activeMeasureItem!.meta);
       }
     }
-    return true;
+  }
+
+  void _cleanMeasureList() {
+    int len = _application.measureItems.length;
+    final needRemoveIdxArr = <int>[];
+    for (int i = 0; i < len; i++) {
+      final item = _application.measureItems[i];
+      if (item.feature == null && item.measuredFeatures.isEmpty) {
+        needRemoveIdxArr.add(i);
+      }
+    }
+    if (needRemoveIdxArr.isNotEmpty) {
+      final arr = needRemoveIdxArr.reversed;
+      for (var i in arr) {
+        _application.measureItems.removeAt(i);
+      }
+    }
   }
 
   bool _undoOnceAnnotation(_AnnotationModel record) {

+ 1 - 1
lib/view/player/controller.dart

@@ -125,7 +125,7 @@ class VidPlayerController extends ChangeNotifier implements IPlayerController {
 
   @override
   Future<bool> load() async {
-    final loaded = await _dataChannel.load(3 * 1000);
+    final loaded = await _dataChannel.load(10 * 1000);
     if (loaded) {
       _setStatus(VidPlayStatus.ready);
     } else {

+ 35 - 0
pubspec.lock

@@ -50,6 +50,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "1.2.1"
+  charcode:
+    dependency: transitive
+    description:
+      name: charcode
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.3.1"
   clock:
     dependency: transitive
     description:
@@ -78,6 +85,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "3.0.2"
+  csslib:
+    dependency: transitive
+    description:
+      name: csslib
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "0.17.2"
   custom_pop_up_menu:
     dependency: transitive
     description:
@@ -321,6 +335,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "2.1.1"
+  html:
+    dependency: transitive
+    description:
+      name: html
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "0.15.1"
   http:
     dependency: transitive
     description:
@@ -571,6 +592,20 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "1.3.0"
+  universal_html:
+    dependency: "direct main"
+    description:
+      name: universal_html
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.8"
+  universal_io:
+    dependency: transitive
+    description:
+      name: universal_io
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.4"
   url_launcher:
     dependency: "direct main"
     description: