Skip to content

Commit

Permalink
Turn off Google Translate for mathfield. Reject some pointer moves wh…
Browse files Browse the repository at this point in the history
…en double-clicking.
  • Loading branch information
arnog committed Apr 6, 2019
1 parent b77dedf commit 71a9b2e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/editor/editor-mathfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,16 @@ MathField.prototype._onPointerDown = function(evt) {
function onPointerMove(evt) {
const x = evt.touches ? evt.touches[0].clientX : evt.clientX;
const y = evt.touches ? evt.touches[0].clientY : evt.clientY;

// Ignore events that are within small spatial and temporal bounds
// of the pointer down
if (Date.now() < anchorTime + 500 &&
Math.abs(anchorX - x) < 5 && Math.abs(anchorY - y) < 5) {
evt.preventDefault();
evt.stopPropagation();
return;
}

let actualAnchor = anchor;

if (evt.touches && evt.touches.length === 2) {
Expand All @@ -578,6 +588,7 @@ MathField.prototype._onPointerDown = function(evt) {
const focus = that._pathFromPoint(x, y,
{bias: x <= anchorX ? (x === anchorX ? 0 : -1) : +1});


if (focus && that.mathlist.setRange(actualAnchor, focus,
{extendToWordBoundary: trackingWords})) {
// Re-render if the range has actually changed
Expand Down Expand Up @@ -609,6 +620,7 @@ MathField.prototype._onPointerDown = function(evt) {

const anchorX = evt.touches ? evt.touches[0].clientX : evt.clientX;
const anchorY = evt.touches ? evt.touches[0].clientY : evt.clientY;
const anchorTime = Date.now();
const bounds = this.element.getBoundingClientRect();
if (anchorX >= bounds.left && anchorX <= bounds.right &&
anchorY >= bounds.top && anchorY <= bounds.bottom) {
Expand Down Expand Up @@ -1779,6 +1791,9 @@ MathField.prototype._render = function(renderOptions) {

const base = Span.makeSpan(spans, 'ML__base');
base.attributes = {
// Sometimes Google Translate kicks in an attempts to 'translate' math
// This doesn't work very well, so turn off translate
'translate': 'no',
// Hint to screen readers to not attempt to read this span
// They should use instead the 'aria-label' below.
'aria-hidden': 'true'
Expand Down Expand Up @@ -2175,6 +2190,7 @@ MathField.prototype.pasteFromClipboard_ = function() {
}



/**
* This method can be invoked as a selector with {@linkcode MathField#$perform $perform("insert")}
* or called explicitly.
Expand Down

0 comments on commit 71a9b2e

Please sign in to comment.