Skip to content

Commit 765dcae

Browse files
add api documentation
1 parent d170523 commit 765dcae

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

docs/Api_Methods.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,33 @@ If the cursor is before the plus this method would return:
173173
{
174174
latex: 'a+b',
175175
startIndex: 1,
176-
endIndex: 1
176+
endIndex: 1,
177+
opaqueSnapshot: {...}
177178
}
178179
```
179180

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+
const selection = 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+
const selection = mq.selection(); // takes a snapshot of the selection
199+
mq.latex('123');
200+
mq.selection(selection); // will restore the selection
201+
```
202+
180203
# Editable MathField methods
181204

182205
Editable math fields have all of the [above](#mathquill-base-methods) methods in addition to the ones listed here.

0 commit comments

Comments
 (0)