pull/13/head
singerdmx 4 years ago
parent b40b0f63f2
commit 62af37fbbb
  1. 3
      lib/models/rules/insert.dart
  2. 14
      lib/models/rules/rule.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;

@ -54,16 +54,20 @@ 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) {
try {
final result = rule.apply(delta, index,
len: len, data: data, attribute: attribute);
if (result != null) {
print("Rule $rule applied");
return delta..trim();
return result..trim();
}
} catch (e) {
throw e;
}
}
throw ('Apply rules failed');

Loading…
Cancel
Save