[closes gh-130] Virtual keyboard should no longer appear when output has focus. Fixed infotip touch handling.
This commit is contained in:
Родитель
1f37f4a282
Коммит
2f6f1c40bd
|
@ -41,36 +41,44 @@
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var activeTimeout;
|
|
||||||
function mousemove(e) {
|
function mousemove(e) {
|
||||||
/* eslint-disable no-invalid-this */
|
/* eslint-disable no-invalid-this */
|
||||||
if (activeTimeout) {
|
delayedInteraction(this.CodeMirror, e.pageX, e.pageY);
|
||||||
clearTimeout(activeTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
var wrapper = this;
|
|
||||||
activeTimeout = setTimeout(function() {
|
|
||||||
processMoveOrClick.call(wrapper, e);
|
|
||||||
activeTimeout = null;
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseout(e) {
|
function mouseout(e) {
|
||||||
|
/* eslint-disable no-invalid-this */
|
||||||
var cm = this.CodeMirror;
|
var cm = this.CodeMirror;
|
||||||
if (e.target !== cm.getWrapperElement())
|
if (e.target !== cm.getWrapperElement())
|
||||||
return;
|
return;
|
||||||
tooltip.hide();
|
tooltip.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
function click(e) {
|
function touchstart(e) {
|
||||||
processMoveOrClick.call(this, e);
|
/* eslint-disable no-invalid-this */
|
||||||
|
delayedInteraction(this.CodeMirror, e.touches[0].pageX, e.touches[0].pageY);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processMoveOrClick(e) {
|
function click(e) {
|
||||||
/* eslint-disable no-invalid-this */
|
/* eslint-disable no-invalid-this */
|
||||||
var cm = this.CodeMirror;
|
interaction(this.CodeMirror, e.pageX, e.pageY);
|
||||||
|
}
|
||||||
|
|
||||||
var coords = cm.coordsChar({ left: e.x, top: e.y });
|
var activeTimeout;
|
||||||
|
function delayedInteraction(cm, x, y) {
|
||||||
|
/* eslint-disable no-invalid-this */
|
||||||
|
if (activeTimeout) {
|
||||||
|
clearTimeout(activeTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
activeTimeout = setTimeout(function() {
|
||||||
|
interaction(cm, x, y);
|
||||||
|
activeTimeout = null;
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function interaction(cm, x, y) {
|
||||||
|
var coords = cm.coordsChar({ left: x, top: y });
|
||||||
var getTipContent = cm.state.infotip.getTipContent || cm.getHelper(coords, "infotip");
|
var getTipContent = cm.state.infotip.getTipContent || cm.getHelper(coords, "infotip");
|
||||||
if (!getTipContent) {
|
if (!getTipContent) {
|
||||||
tooltip.hide();
|
tooltip.hide();
|
||||||
|
@ -78,6 +86,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var token = cm.getTokenAt(coords);
|
var token = cm.getTokenAt(coords);
|
||||||
|
if (token === tooltip.token)
|
||||||
|
return;
|
||||||
|
|
||||||
|
tooltip.token = token;
|
||||||
var content = getTipContent(cm, token);
|
var content = getTipContent(cm, token);
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
tooltip.hide();
|
tooltip.hide();
|
||||||
|
@ -94,9 +106,10 @@
|
||||||
var wrapper = cm.getWrapperElement();
|
var wrapper = cm.getWrapperElement();
|
||||||
var state = cm.state.infotip;
|
var state = cm.state.infotip;
|
||||||
if (old && old !== CodeMirror.Init && state) {
|
if (old && old !== CodeMirror.Init && state) {
|
||||||
CodeMirror.off(wrapper, "click", click);
|
CodeMirror.off(wrapper, "click", click);
|
||||||
CodeMirror.off(wrapper, "mousemove", mousemove);
|
CodeMirror.off(wrapper, "touchstart", touchstart);
|
||||||
CodeMirror.off(wrapper, "mouseout", mouseout);
|
CodeMirror.off(wrapper, "mousemove", mousemove);
|
||||||
|
CodeMirror.off(wrapper, "mouseout", mouseout);
|
||||||
delete cm.state.infotip;
|
delete cm.state.infotip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +120,9 @@
|
||||||
getTipContent: options.getTipContent
|
getTipContent: options.getTipContent
|
||||||
};
|
};
|
||||||
cm.state.infotip = state;
|
cm.state.infotip = state;
|
||||||
CodeMirror.on(wrapper, "click", click);
|
CodeMirror.on(wrapper, "click", click);
|
||||||
CodeMirror.on(wrapper, "mousemove", mousemove);
|
CodeMirror.on(wrapper, "touchstart", touchstart);
|
||||||
CodeMirror.on(wrapper, "mouseout", mouseout);
|
CodeMirror.on(wrapper, "mousemove", mousemove);
|
||||||
|
CodeMirror.on(wrapper, "mouseout", mouseout);
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -36,6 +36,10 @@ Vue.component('app-mirrorsharp-readonly', {
|
||||||
const wrapper = cm.getWrapperElement();
|
const wrapper = cm.getWrapperElement();
|
||||||
wrapper.classList.add('mirrorsharp-theme');
|
wrapper.classList.add('mirrorsharp-theme');
|
||||||
|
|
||||||
|
const codeElement = wrapper.getElementsByClassName('CodeMirror-code')[0];
|
||||||
|
if (codeElement && codeElement.contentEditable) // HACK, mobile only
|
||||||
|
codeElement.contentEditable = false;
|
||||||
|
|
||||||
this.$watch('language', value => {
|
this.$watch('language', value => {
|
||||||
cm.setOption('mode', modeMap[value]);
|
cm.setOption('mode', modeMap[value]);
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче