pull/13/head
singerdmx 4 years ago
parent b40b0f63f2
commit 62af37fbbb
  1. 3
      lib/models/rules/insert.dart
  2. 18
      lib/models/rules/rule.dart

@ -250,7 +250,8 @@ class ForceNewlineForInsertsAroundEmbedRule extends InsertRule {
String text = data as String; String text = data as String;
DeltaIterator itr = DeltaIterator(document); 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 cursorBeforeEmbed = cur.data is! String;
bool cursorAfterEmbed = prev != null && prev.data is! String; bool cursorAfterEmbed = prev != null && prev.data is! String;

@ -54,18 +54,22 @@ class Rules {
Delta apply(RuleType ruleType, Document document, int index, Delta apply(RuleType ruleType, Document document, int index,
{int len, Object data, Attribute attribute}) { {int len, Object data, Attribute attribute}) {
Delta delta = document.toDelta(); final delta = document.toDelta();
for (var rule in _rules) { for (var rule in _rules) {
if (rule.type != ruleType) { if (rule.type != ruleType) {
continue; continue;
} }
delta = try {
rule.apply(delta, index, len: len, data: data, attribute: attribute); final result = rule.apply(delta, index,
if (delta != null) { len: len, data: data, attribute: attribute);
print("Rule $rule applied"); if (result != null) {
return delta..trim(); print("Rule $rule applied");
return result..trim();
}
} catch (e) {
throw e;
} }
} }
throw('Apply rules failed'); throw ('Apply rules failed');
} }
} }

Loading…
Cancel
Save