{"size": 891, "ext": "js", "max_stars_repo_path": "src/actions/distance_key_press.js", "max_stars_repo_name": "baileyforrest/poepad", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/actions/distance_key_press.js", "max_issues_repo_name": "baileyforrest/poepad", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/actions/distance_key_press.js", "max_forks_repo_name": "baileyforrest/poepad", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.8, "max_line_length": 47, "alphanum_fraction": 0.5364758698}

let KeyPress = require('./key_press');
const DELAY = 15;

class DistanceKeyPress extends KeyPress {
  constructor(input, key, distance) {
    super(input, key, distance);
    this.distance = distance;
    this.pending = false;
  }

  onPressChanged(pressed) {
    if (this.pending) {
      return;
    }

    let on_unpressed = () => {
      this.toggle(false);
      this.input.overrideRadius(null);
    };

    if (pressed) {
      this.pending = true;
      this.input.overrideRadius(this.distance);
      setTimeout(() => {
        this.toggle(true)
        if (this.pressed) {
          this.pending = false;
        } else {
          setTimeout(() => {
            this.pending = false;
            on_unpressed();
          }, DELAY);
        }
      }, DELAY);
    } else {
      if (!this.pending) {
        on_unpressed();
      }
    }
  }
}

module.exports = DistanceKeyPress;
