|
@@ -161,10 +161,24 @@ class NotusDocument {
|
161
|
161
|
/// unchanged and no [NotusChange] is published to [changes] stream.
|
162
|
162
|
Delta format(int index, int length, NotusAttribute attribute) {
|
163
|
163
|
assert(index >= 0 && length >= 0 && attribute != null);
|
164
|
|
- final change = _heuristics.applyFormatRules(this, index, length, attribute);
|
165
|
|
- if (change.isNotEmpty) {
|
166
|
|
- compose(change, ChangeSource.local);
|
|
164
|
+
|
|
165
|
+ Delta change = Delta();
|
|
166
|
+
|
|
167
|
+ if (attribute is EmbedAttribute && length > 0) {
|
|
168
|
+ // Must delete selected length of text before applying embed attribute
|
|
169
|
+ // since inserting an embed in non-empty selection is essentially a
|
|
170
|
+ // replace operation.
|
|
171
|
+ change = delete(index, length);
|
|
172
|
+ length = 0;
|
167
|
173
|
}
|
|
174
|
+
|
|
175
|
+ final formatChange =
|
|
176
|
+ _heuristics.applyFormatRules(this, index, length, attribute);
|
|
177
|
+ if (formatChange.isNotEmpty) {
|
|
178
|
+ compose(formatChange, ChangeSource.local);
|
|
179
|
+ change = change.compose(formatChange);
|
|
180
|
+ }
|
|
181
|
+
|
168
|
182
|
return change;
|
169
|
183
|
}
|
170
|
184
|
|