<commit_before>/* global atom document:true */
import clipboardy = require('clipboardy');

export class KillRing {
  buffer: string[][];
  sealed: boolean;

  constructor(buffer: string[][]) {
    this.buffer = buffer;
    this.sealed = true;
  }

  put(texts: string[], forward: boolean = true) {
    if (this.sealed) this.push(texts);
    else this.update(texts, forward);
  }

  seal() {
    this.sealed = true;
  }

  push(texts: string[]) {
    this.buffer.unshift(texts);
    clipboardy.writeSync(texts.join('\n'));
    while (this.buffer.length > 10) this.buffer.pop();
    this.sealed = false;
  }

  update(texts: string[], forward: boolean) {
    const lasts = this.buffer.shift() || [];
    const newTexts = texts.map((t, i) =>
      forward ? lasts[i] + (t ? t : '') : (t ? t : '') + lasts[i]
    );
    this.push(newTexts);
  }

  top() {
    this.updateBuffer();
    return this.buffer[0];
  }

  updateBuffer() {
    const lasts = this.buffer[0];
    let read = clipboardy.readSync();
    if (lasts ? lasts.join('\n') : '' !== read) this.push(read.split('\n'));<commit_msg>Fix multiple push<commit_after>/* global atom document:true */
import clipboardy = require('clipboardy');

export class KillRing {
  buffer: string[][];
  sealed: boolean;

  constructor(buffer: string[][]) {
    this.buffer = buffer;
    this.sealed = true;
  }

  put(texts: string[], forward: boolean = true) {
    if (this.sealed) this.push(texts);
    else this.update(texts, forward);
  }

  seal() {
    this.sealed = true;
  }

  push(texts: string[]) {
    this.buffer.unshift(texts);
    clipboardy.writeSync(texts.join('\n'));
    while (this.buffer.length > 10) this.buffer.pop();
    this.sealed = false;
  }

  update(texts: string[], forward: boolean) {
    const lasts = this.buffer.shift() || [];
    const newTexts = texts.map((t, i) =>
      forward ? lasts[i] + (t ? t : '') : (t ? t : '') + lasts[i]
    );
    this.push(newTexts);
  }

  top() {
    this.updateBuffer();
    return this.buffer[0];
  }

  updateBuffer() {
    const lasts = this.buffer[0];
    const laststr = lasts ? lasts.join('\n') : '';
    const read = clipboardy.readSync();
    if (laststr !== read) this.push(read.split('\n'));
{'fraction_non_alphanumeric': 0.1863410221619177, 'fraction_numerical': 0.003618272274988693, 'mean_word_length': 3.029143897996357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2592501', 'n_tokens_mistral': 793, 'n_tokens_neox': 777, 'n_words': 162}