You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Api_Methods.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,10 +173,33 @@ If the cursor is before the plus this method would return:
173
173
{
174
174
latex:'a+b',
175
175
startIndex:1,
176
-
endIndex:1
176
+
endIndex:1,
177
+
opaqueSnapshot: {...}
177
178
}
178
179
```
179
180
181
+
You can pass the result of `.selection()` back into `.selection()` to restore a cursor / selection. This works by taking a snapshot of the selection you currently have and recording
182
+
enough information to restore it within `opaqueSnapshot`. You should not peek inside of `opaqueSnapshot` or permanently store it. This is valid only for this version of MathQuill. This selection is also only valid if the MQ's latex is identical. The MQ can go through changes, but when you try to restore the selection the current latex must match the latex when the selection snapshot was created.
183
+
184
+
```js
185
+
// this would work
186
+
mq.latex('abc');
187
+
mq.select();
188
+
constselection=mq.selection(); // takes a snapshot of the selection
189
+
mq.latex('123');
190
+
mq.latex('abc');
191
+
mq.selection(selection); // will restore the selection
192
+
```
193
+
194
+
```js
195
+
// this would not work
196
+
mq.latex('abc');
197
+
mq.select();
198
+
constselection=mq.selection(); // takes a snapshot of the selection
199
+
mq.latex('123');
200
+
mq.selection(selection); // will restore the selection
201
+
```
202
+
180
203
# Editable MathField methods
181
204
182
205
Editable math fields have all of the [above](#mathquill-base-methods) methods in addition to the ones listed here.
0 commit comments