<commit_before>var places = require('places/places.js')
var autocomplete = require('util/autocomplete.js')

const bookmarkEditor = {
  currentInstance: null,
  getTagElement: function (tag, selected, onClick, options = {}) {
    var el = document.createElement('button')
    el.className = 'tag'
    el.textContent = tag
    if (selected) {
      el.classList.add('selected')
      el.setAttribute('aria-pressed', true)
    } else {
      el.classList.add('suggested')
      el.setAttribute('aria-pressed', false)
    }
    el.addEventListener('click', function () {
      onClick()
      if (el.classList.contains('selected') && options.autoRemove !== false) {
        el.remove()
      } else {
        el.classList.remove('suggested')
        el.classList.add('selected')
      }
    })
    return el
  },
  render: async function (url, options = {}) {
    bookmarkEditor.currentInstance = {}
    // TODO make places API return a promise
    bookmarkEditor.currentInstance.bookmark = (await new Promise(function (resolve, reject) {
      places.getItem(url, item => resolve(item))
    }))

    var editor = document.createElement('div')
    editor.className = 'bookmark-editor searchbar-item'

    if (options.simplified) {
      editor.className += ' simplified'
    }

    if (!options.simplified) {
      // title input
      var title = document.createElement('span')
      title.className = 'title wide'
      title.textContent = bookmarkEditor.currentInstance.bookmark.title
      editor.appendChild(title)

      // URL
      var URLSpan = document.createElement('div')
      URLSpan.className = 'bookmark-url'
      URLSpan.textContent = bookmarkEditor.currentInstance.bookmark.url
      editor.appendChild(URLSpan)
    }

    // tag area
    var tagArea = document.createElement('div')
    tagArea.className = 'tag-edit-area'
    editor.appendChild(tagArea)

    if (!options.simplified) {
      // save button
      var saveButton = document.createElement('button')
      saveButton.className = 'action-button always-visible i carbon:checkmark'
      saveButton.tabIndex = -1
      editor.appendChild(saveButton)
      saveButton.addEventListener('click', function () {
        editor.remove()
        bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark)
        bookmarkEditor.currentInstance = null
      })
    }

    // delete button
    var delButton = document.createElement('button')
    delButton.className = 'action-button always-visible bookmark-delete-button i carbon:delete'
    delButton.tabIndex = -1
    editor.appendChild(delButton)
    delButton.addEventListener('click', function () {
      editor.remove()
      bookmarkEditor.currentInstance.onClose(null)
      bookmarkEditor.currentInstance = null
    })

    var tags = {
      selected: [],
      suggested: []
    }

    // show tags<commit_msg>Update carbon iconfont references (#2025)<commit_after>var places = require('places/places.js')
var autocomplete = require('util/autocomplete.js')

const bookmarkEditor = {
  currentInstance: null,
  getTagElement: function (tag, selected, onClick, options = {}) {
    var el = document.createElement('button')
    el.className = 'tag'
    el.textContent = tag
    if (selected) {
      el.classList.add('selected')
      el.setAttribute('aria-pressed', true)
    } else {
      el.classList.add('suggested')
      el.setAttribute('aria-pressed', false)
    }
    el.addEventListener('click', function () {
      onClick()
      if (el.classList.contains('selected') && options.autoRemove !== false) {
        el.remove()
      } else {
        el.classList.remove('suggested')
        el.classList.add('selected')
      }
    })
    return el
  },
  render: async function (url, options = {}) {
    bookmarkEditor.currentInstance = {}
    // TODO make places API return a promise
    bookmarkEditor.currentInstance.bookmark = (await new Promise(function (resolve, reject) {
      places.getItem(url, item => resolve(item))
    }))

    var editor = document.createElement('div')
    editor.className = 'bookmark-editor searchbar-item'

    if (options.simplified) {
      editor.className += ' simplified'
    }

    if (!options.simplified) {
      // title input
      var title = document.createElement('span')
      title.className = 'title wide'
      title.textContent = bookmarkEditor.currentInstance.bookmark.title
      editor.appendChild(title)

      // URL
      var URLSpan = document.createElement('div')
      URLSpan.className = 'bookmark-url'
      URLSpan.textContent = bookmarkEditor.currentInstance.bookmark.url
      editor.appendChild(URLSpan)
    }

    // tag area
    var tagArea = document.createElement('div')
    tagArea.className = 'tag-edit-area'
    editor.appendChild(tagArea)

    if (!options.simplified) {
      // save button
      var saveButton = document.createElement('button')
      saveButton.className = 'action-button always-visible i carbon:checkmark'
      saveButton.tabIndex = -1
      editor.appendChild(saveButton)
      saveButton.addEventListener('click', function () {
        editor.remove()
        bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark)
        bookmarkEditor.currentInstance = null
      })
    }

    // delete button
    var delButton = document.createElement('button')
    delButton.className = 'action-button always-visible bookmark-delete-button i carbon:trash-can'
    delButton.tabIndex = -1
    editor.appendChild(delButton)
    delButton.addEventListener('click', function () {
      editor.remove()
      bookmarkEditor.currentInstance.onClose(null)
      bookmarkEditor.currentInstance = null
    })

    var tags = {
      selected: [],
      suggested: []
    }

    // show tags
{'fraction_non_alphanumeric': 0.12032689966962268, 'fraction_numerical': 0.0013910624239262736, 'mean_word_length': 2.945130315500686, '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': '6588218', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1586, 'n_words': 311}