<commit_before>/**
 * Alt+Click handler module: exports methods for handling all alt+click-related events in the
 * terminal.
 * @module xterm/handlers/AltClickHandler
 * @license MIT
 */

import { Terminal } from '../Terminal';
import { CHAR_DATA_WIDTH_INDEX } from '../Buffer';
import { C0 } from '../EscapeSequences';

export class AltClickHandler {
  private _terminal: Terminal;
  private _mouseRow: number;
  private _mouseCol: number;
  private _mouseEvent: MouseEvent;

  constructor(mouseEvent: MouseEvent, terminal: Terminal) {
    this._terminal = terminal;

    [this._mouseCol, this._mouseRow] = this._terminal.mouseHelper.getCoords(
      (this._mouseEvent = mouseEvent),
      this._terminal.element,
      this._terminal.charMeasure,
      this._terminal.options.lineHeight,
      this._terminal.cols,
      this._terminal.rows,
      true
    ).map((coordinate: number) => {
      return coordinate - 1;
    });
  }

  public move(): void {
    if (!this._mouseEvent.altKey) return;

    let keyboardArrows;

    if (this._terminal.buffer === this._terminal.buffers.normal) {
      keyboardArrows = this.buildArrowSequence(this.normalCharCount(), this.horizontalCursorCommand(this.normalMoveForward()));
    } else {
      keyboardArrows = this.buildArrowSequence(this.altVerticalCharCount(), this.verticalCursorCommand(this.altMoveUpward()));
      keyboardArrows += this.buildArrowSequence(this.altHorizontalCharCount(), this.horizontalCursorCommand(this.altMoveForward()));
    }

    this._terminal.send(keyboardArrows);
  }

  private buildArrowSequence(count: number, sequence: string): string {
    return Array(count).join(sequence);
  }<commit_msg>Handle going back and up in the alt buffer from a long line to a short line<commit_after>/**
 * Alt+Click handler module: exports methods for handling all alt+click-related events in the
 * terminal.
 * @module xterm/handlers/AltClickHandler
 * @license MIT
 */

import { Terminal } from '../Terminal';
import { CHAR_DATA_WIDTH_INDEX } from '../Buffer';
import { C0 } from '../EscapeSequences';

export class AltClickHandler {
  private _terminal: Terminal;
  private _mouseRow: number;
  private _mouseCol: number;
  private _mouseEvent: MouseEvent;

  constructor(mouseEvent: MouseEvent, terminal: Terminal) {
    this._terminal = terminal;

    [this._mouseCol, this._mouseRow] = this._terminal.mouseHelper.getCoords(
      (this._mouseEvent = mouseEvent),
      this._terminal.element,
      this._terminal.charMeasure,
      this._terminal.options.lineHeight,
      this._terminal.cols,
      this._terminal.rows,
      true
    ).map((coordinate: number) => {
      return coordinate - 1;
    });
  }

  public move(): void {
    if (!this._mouseEvent.altKey) return;

    let keyboardArrows;

    if (this._terminal.buffer === this._terminal.buffers.normal) {
      keyboardArrows = this.buildArrowSequence(this.normalCharCount(), this.horizontalCursorCommand(this.normalMoveForward()));
    } else {
      let verticalChars = this.buildArrowSequence(this.altVerticalCharCount(), this.verticalCursorCommand(this.altMoveUpward()));
      let horizontalChars = this.buildArrowSequence(this.altHorizontalCharCount(), this.horizontalCursorCommand(this.altMoveForward()));

      if (this.altMoveForward()) {
        keyboardArrows = verticalChars + horizontalChars
      } else {
        keyboardArrows = horizontalChars + verticalChars
      }
    }

    this._terminal.send(keyboardArrows);
  }

  private buildArrowSequence(count: number, sequence: string): string {
    return Array(count).join(sequence);
  }
{'fraction_non_alphanumeric': 0.11476323119777158, 'fraction_numerical': 0.0011142061281337048, 'mean_word_length': 3.9057377049180326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7126862', 'n_tokens_mistral': 1039, 'n_tokens_neox': 996, 'n_words': 221}