Skip to content

Commit 6c22112

Browse files
committed
Fix bogus readInput firing on context menu
Issue #2481
1 parent 18fbcd2 commit 6c22112

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/codemirror.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@
31103110
// The prevInput test prevents this from firing when a context
31113111
// menu is closed (since the resetInput would kill the
31123112
// select-all detection hack)
3113-
if (!cm.curOp && cm.display.prevInput != "\u200b") {
3113+
if (!cm.curOp && cm.display.selForContextMenu == cm.doc.sel) {
31143114
resetInput(cm);
31153115
if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
31163116
}
@@ -3158,14 +3158,16 @@
31583158
resetInput(cm);
31593159
// Adds "Select all" to context menu in FF
31603160
if (!cm.somethingSelected()) display.input.value = display.prevInput = " ";
3161+
display.selForContextMenu = cm.doc.sel;
31613162

31623163
// Select-all will be greyed out if there's nothing to select, so
31633164
// this adds a zero-width space so that we can later check whether
31643165
// it got selected.
31653166
function prepareSelectAllHack() {
31663167
if (display.input.selectionStart != null) {
3167-
var extval = display.input.value = "\u200b" + (cm.somethingSelected() ? display.input.value : "");
3168-
display.prevInput = "\u200b";
3168+
var selected = cm.somethingSelected();
3169+
var extval = display.input.value = "\u200b" + (selected ? display.input.value : "");
3170+
display.prevInput = selected ? "" : "\u200b";
31693171
display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
31703172
}
31713173
}
@@ -3180,7 +3182,7 @@
31803182
if (!ie || ie_upto8) prepareSelectAllHack();
31813183
clearTimeout(detectingSelectAll);
31823184
var i = 0, poll = function() {
3183-
if (display.prevInput == "\u200b" && display.input.selectionStart == 0)
3185+
if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0)
31843186
operation(cm, commands.selectAll)(cm);
31853187
else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
31863188
else resetInput(cm);

0 commit comments

Comments
 (0)