diff --git a/lib/models/rules/insert.dart b/lib/models/rules/insert.dart index 557277db..b62eb26d 100644 --- a/lib/models/rules/insert.dart +++ b/lib/models/rules/insert.dart @@ -250,7 +250,8 @@ class ForceNewlineForInsertsAroundEmbedRule extends InsertRule { String text = data as String; DeltaIterator itr = DeltaIterator(document); - Operation prev = itr.skip(index), cur = itr.next(); + final prev = itr.skip(index); + final cur = itr.next(); bool cursorBeforeEmbed = cur.data is! String; bool cursorAfterEmbed = prev != null && prev.data is! String; diff --git a/lib/models/rules/rule.dart b/lib/models/rules/rule.dart index ea41ac50..d0e3bc14 100644 --- a/lib/models/rules/rule.dart +++ b/lib/models/rules/rule.dart @@ -54,18 +54,22 @@ class Rules { Delta apply(RuleType ruleType, Document document, int index, {int len, Object data, Attribute attribute}) { - Delta delta = document.toDelta(); + final delta = document.toDelta(); for (var rule in _rules) { if (rule.type != ruleType) { continue; } - delta = - rule.apply(delta, index, len: len, data: data, attribute: attribute); - if (delta != null) { - print("Rule $rule applied"); - return delta..trim(); + try { + final result = rule.apply(delta, index, + len: len, data: data, attribute: attribute); + if (result != null) { + print("Rule $rule applied"); + return result..trim(); + } + } catch (e) { + throw e; } } - throw('Apply rules failed'); + throw ('Apply rules failed'); } }