<commit_before>import { Color } from "../classes/Color";
import { ClickEventType } from "../classes/Snippets/ClickEvent";
import { HoverEventType } from "../classes/Snippets/HoverEvent";
import { Snippet } from "../classes/Snippets/SnippetTypes/Snippet";

export function legacy_apply_common_formatting<T extends Snippet>(snippet: T, sf: object): T {
  if (sf["bold"] === true) {
      snippet.bold = true
  }
  if (sf["italic"] === true) {
      snippet.italic = true
  }
  if (sf["underlined"] === true) {
      snippet.underlined = true
  }
  if (sf["strikethrough"] === true) {
      snippet.strikethrough = true
  }
  if (sf["obfuscated"] === true) {
      snippet.obfuscated = true
  }

  const unknownColor: Color | undefined = (<any>Color)[sf["color"]]
  if (unknownColor !== undefined) {
      snippet.color = unknownColor
  } else {
      snippet.color = Color.none
  }
  
  if ("insertion" in sf) {
      snippet.insertion = sf["insertion"]
  }

  if ("clickEvent" in sf) {
    //TODO: Test this!
    snippet.click_event_type = sf["clickEvent"]["action"] as ClickEventType
    if (snippet.click_event_type !== ClickEventType.none) {
        snippet.click_event_value = sf["clickEvent"]["value"]
    }
  }

  if ("hoverEvent" in sf) {
      snippet.hover_event_type = sf["hoverEvent"]["action"] as HoverEventType

      /* Can't import show_text */
      if (snippet.hover_event_type !== HoverEventType.none && snippet.hover_event_type !== HoverEventType.show_text) {
          snippet.hover_event_type = sf["hoverEvent"]["value"]
      }
  }

  return snippet
}<commit_msg>Resolved legacy loading of hover and click events<commit_after>import { Color } from "../classes/Color";
import { ClickEventType } from "../classes/Snippets/ClickEvent";
import { HoverEventType } from "../classes/Snippets/HoverEvent";
import { Snippet } from "../classes/Snippets/SnippetTypes/Snippet";

export function legacy_apply_common_formatting<T extends Snippet>(snippet: T, sf: object): T {
  if (sf["bold"] === true) {
      snippet.bold = true
  }
  if (sf["italic"] === true) {
      snippet.italic = true
  }
  if (sf["underlined"] === true) {
      snippet.underlined = true
  }
  if (sf["strikethrough"] === true) {
      snippet.strikethrough = true
  }
  if (sf["obfuscated"] === true) {
      snippet.obfuscated = true
  }

  const unknownColor: Color | undefined = (<any>Color)[sf["color"]]
  if (unknownColor !== undefined) {
      snippet.color = unknownColor
  } else {
      snippet.color = Color.none
  }
  
  if ("insertion" in sf) {
      snippet.insertion = sf["insertion"]
  }

  if ("clickEvent" in sf) {
    const foundCEType: ClickEventType | undefined = (<any>ClickEventType)[sf["clickEvent"]["action"]]
    if (foundCEType !== undefined && foundCEType !== ClickEventType.none) {
        snippet.click_event_type = foundCEType
        snippet.click_event_value = sf["clickEvent"]["value"]
    }
  }

  if ("hoverEvent" in sf) {
    const foundHEType: HoverEventType | undefined = (<any>HoverEventType)[sf["hoverEvent"]["action"]]
    if (foundHEType !== undefined
        && foundHEType !== HoverEventType.none
        && foundHEType !== HoverEventType.show_text) {
        snippet.hover_event_type = foundHEType
        snippet.hover_event_value = sf["hoverEvent"]["value"]
    }
  }

  return snippet
}
{'fraction_non_alphanumeric': 0.1512503766194637, 'fraction_numerical': 0.0, 'mean_word_length': 3.4148936170212765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4992425', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1087, 'n_words': 221}