|
@@ -131,8 +131,19 @@ class ZefyrController extends ChangeNotifier {
|
131
|
131
|
}
|
132
|
132
|
|
133
|
133
|
void formatText(int index, int length, NotusAttribute attribute) {
|
134
|
|
- document.format(index, length, attribute);
|
|
134
|
+ final change = document.format(index, length, attribute);
|
135
|
135
|
_lastChangeSource = ChangeSource.local;
|
|
136
|
+ // Transform selection against the composed change and give priority to
|
|
137
|
+ // the change. This is needed in cases when format operation actually
|
|
138
|
+ // inserts data into the document (e.g. embeds).
|
|
139
|
+ final base = change.transformPosition(_selection.baseOffset);
|
|
140
|
+ final extent =
|
|
141
|
+ change.transformPosition(_selection.extentOffset);
|
|
142
|
+ final adjustedSelection =
|
|
143
|
+ _selection.copyWith(baseOffset: base, extentOffset: extent);
|
|
144
|
+ if (_selection != adjustedSelection) {
|
|
145
|
+ _updateSelectionSilent(adjustedSelection, source: _lastChangeSource);
|
|
146
|
+ }
|
136
|
147
|
notifyListeners();
|
137
|
148
|
}
|
138
|
149
|
|