<commit_before>
import 'rangy/lib/rangy-textrange'
import Cursor from './cursor'
import * as content from './content'
import * as parser from './parser'
import config from './config'
import highlightSupport from './highlight-support'
import highlightText from './highlight-text'

/**
 * The Selection module provides a cross-browser abstraction layer for range
 * and selection.
 *
 * @module core
 * @submodule selection
 */
/**
 * Class that represents a selection and provides functionality to access or
 * modify the selection.
 *
 * @class Selection
 * @constructor
 */

export default class Selection extends Cursor {
  constructor () {
    super(...arguments)
    delete this.isCursor
    this.isSelection = true
  }

  // Get the text inside the selection.
  text () {
    return this.range.toString()
  }

  // Get the html inside the selection.
  html () {
    return this.range.toHtml()
  }

  isAllSelected () {
    return parser.isBeginningOfHost(
      this.host,
      this.range.startContainer,
      this.range.startOffset
    ) && parser.isTextEndOfHost(
      this.host,
      this.range.endContainer,
      this.range.endOffset
    )
  }

  getTextRange () {
    return this.range.toCharacterRange(this.host)
  }

  // Get the ClientRects of this selection.
  // Use this if you want more precision than getBoundingClientRect can give.
  getRects () {
    // consider: translate into absolute positions
    // just like Cursor#getCoordinates()
    return this.range.nativeRange.getClientRects()
  }


  link (href, attrs = {}) {
    if (href) attrs.href = href
    const link = this.createElement(config.linkMarkup.name, config.linkMarkup.attribs)
    for (const key in attrs) link.setAttribute(key, attrs[key])
    this.forceWrap(link)
  }<commit_msg>feat(selection): Add a toString() helper function.<commit_after>
import 'rangy/lib/rangy-textrange'
import Cursor from './cursor'
import * as content from './content'
import * as parser from './parser'
import config from './config'
import highlightSupport from './highlight-support'
import highlightText from './highlight-text'

/**
 * The Selection module provides a cross-browser abstraction layer for range
 * and selection.
 *
 * @module core
 * @submodule selection
 */
/**
 * Class that represents a selection and provides functionality to access or
 * modify the selection.
 *
 * @class Selection
 * @constructor
 */

export default class Selection extends Cursor {
  constructor () {
    super(...arguments)
    delete this.isCursor
    this.isSelection = true
  }

  // Get the text inside the selection.
  text () {
    return this.range.toString()
  }

  // Get the html inside the selection.
  html () {
    return this.range.toHtml()
  }

  isAllSelected () {
    return parser.isBeginningOfHost(
      this.host,
      this.range.startContainer,
      this.range.startOffset
    ) && parser.isTextEndOfHost(
      this.host,
      this.range.endContainer,
      this.range.endOffset
    )
  }

  getTextRange () {
    return this.range.toCharacterRange(this.host)
  }

  // Return a plain string of the current selection content.
  toString () {
    return this.range.toString()
  }

  // Get the ClientRects of this selection.
  // Use this if you want more precision than getBoundingClientRect can give.
  getRects () {
    // consider: translate into absolute positions
    // just like Cursor#getCoordinates()
    return this.range.nativeRange.getClientRects()
  }


  link (href, attrs = {}) {
    if (href) attrs.href = href
    const link = this.createElement(config.linkMarkup.name, config.linkMarkup.attribs)
    for (const key in attrs) link.setAttribute(key, attrs[key])
    this.forceWrap(link)
  }
{'fraction_non_alphanumeric': 0.10633116883116883, 'fraction_numerical': 0.0, 'mean_word_length': 3.0760749724366043, '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': '868439', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1057, 'n_words': 321}