<commit_before>import { Command, TextRange } from "./types";
import { TextApi, TextState } from "./types/CommandOptions";
import { insertText } from "./util/InsertTextAtPosition";

export interface CommandOrchestrator {
  executeCommand(command: Command): void;
}

export class TextAreaTextApi implements TextApi {
  textArea: HTMLTextAreaElement;

  constructor(textArea: HTMLTextAreaElement) {
    this.textArea = textArea;
  }

  replaceSelection(text: string): TextState {
    insertText(this.textArea, text);
    return getStateFromTextArea(this.textArea);
  }

  setSelectionRange(selection: TextRange): TextState {
    this.textArea.focus();
    this.textArea.selectionStart = selection.start;
    this.textArea.selectionEnd = selection.end;
    return getStateFromTextArea(this.textArea);
  }<commit_msg>feat: add method for manually retrieving the TextState<commit_after>import { Command, TextRange } from "./types";
import { TextApi, TextState } from "./types/CommandOptions";
import { insertText } from "./util/InsertTextAtPosition";

export interface CommandOrchestrator {
  executeCommand(command: Command): void;
}

export class TextAreaTextApi implements TextApi {
  textArea: HTMLTextAreaElement;

  constructor(textArea: HTMLTextAreaElement) {
    this.textArea = textArea;
  }

  replaceSelection(text: string): TextState {
    insertText(this.textArea, text);
    return getStateFromTextArea(this.textArea);
  }

  setSelectionRange(selection: TextRange): TextState {
    this.textArea.focus();
    this.textArea.selectionStart = selection.start;
    this.textArea.selectionEnd = selection.end;
    return getStateFromTextArea(this.textArea);
  }
  
  getState(): TextState {
    return getStateFromTextArea(this.textArea);
  }
{'fraction_non_alphanumeric': 0.10423825887743414, 'fraction_numerical': 0.0, 'mean_word_length': 4.942176870748299, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6784755', 'n_tokens_mistral': 502, 'n_tokens_neox': 495, 'n_words': 107}