Skip to content

Commit df2216c

Browse files
Merge pull request #323 from desmosinc/mike/fix-restore-selection
make sure cursor is added back in when restoring collapsed selection
2 parents 92ef9ed + 4734928 commit df2216c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/services/latex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ class Controller_latex extends Controller_keystroke {
180180
const lastInstruction = path[lastInstructionI];
181181
if (lastInstruction === 'D') {
182182
this.cursor.clearSelection().endSelection();
183-
this.cursor.insAtLeftEnd(node);
183+
this.notify('move').cursor.insAtLeftEnd(node);
184184
return true;
185185
} else if (lastInstruction === 'R') {
186186
this.cursor.clearSelection().endSelection();
187-
this.cursor.insRightOf(node);
187+
this.notify('move').cursor.insRightOf(node);
188188
return true;
189189
} else {
190190
return false;

test/unit/publicapi.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,53 @@ suite('Public API', function () {
282282
assert.equal(mq.isUserSelecting(), false);
283283
});
284284

285+
test('selection restoration shows blinking cursor', function () {
286+
mq.latex('a+b+c');
287+
mq.focus();
288+
289+
assert.ok(
290+
mq.el().querySelector('.mq-cursor'),
291+
'cursor shows up to start'
292+
);
293+
294+
// Create a selection covering entire content
295+
mq.select();
296+
var selectionSnapshot = mq.selection();
297+
298+
assert.ok(
299+
!mq.el().querySelector('.mq-cursor'),
300+
'cursor should not be in DOM during selection'
301+
);
302+
303+
// Move to a single cursor position (no selection)
304+
mq.moveToLeftEnd();
305+
var caretSnapshot = mq.selection();
306+
307+
assert.ok(
308+
mq.el().querySelector('.mq-cursor'),
309+
'cursor should be in DOM at single position'
310+
);
311+
assert.equal(
312+
caretSnapshot.startIndex,
313+
caretSnapshot.endIndex,
314+
'should be a caret position'
315+
);
316+
317+
// Restore the full selection
318+
mq.selection(selectionSnapshot);
319+
assert.ok(
320+
!mq.el().querySelector('.mq-cursor'),
321+
'cursor should not be in DOM during selection'
322+
);
323+
324+
// Now restore the single caret position - this should show the blinking cursor
325+
mq.selection(caretSnapshot);
326+
assert.ok(
327+
mq.el().querySelector('.mq-cursor'),
328+
'cursor should be in DOM and visible after restoring caret position'
329+
);
330+
});
331+
285332
test('.mathspeak()', function () {
286333
function assertMathSpeakEqual(a, b) {
287334
assert.equal(normalize(a), normalize(b));

0 commit comments

Comments
 (0)