<commit_before>Scribe = require('../scribe')


enterEditMode = (url) ->
  url = 'https://' + url unless /^http[s]?:\/\//.test(url)
  @tooltipInput.value = url
  Scribe.DOM.addClass(@tooltip, 'editing')

exitEditMode = ->
  if @tooltipLink.innerText != @tooltipInput.value
    @tooltipLink.innerText = @tooltipLink.href = @tooltipInput.value
    @editor.selection.format('link', @tooltipInput.value, { source: 'user' })
    @toolbar.emit(Scribe.Toolbar.events.FORMAT, 'link', @tooltipInput.value)
  Scribe.DOM.removeClass(@tooltip, 'editing')

hideTooltip = ->
  @tooltip.style.left = '-10000px'

initListeners = ->
  @editor.root.addEventListener('click', (event) =>
    if event.target?.tagName == 'A'
      @tooltipLink.innerText = @tooltipLink.href = event.target.href
      Scribe.DOM.removeClass(@tooltip, 'editing')
      showTooptip.call(this, event.target, @tooltip.offsetParent, @editor.root)
    else
      hideTooltip.call(this)
  )
  @button.addEventListener('click', =>
    value = null
    if Scribe.DOM.hasClass(@button, 'active')
      value = false
    else
      range = @editor.selection.getRange()
      enterEditMode.call(this, range.getText())
      Scribe.DOM.addClass(@tooltip, 'editing')
      showTooptip.call(this, @editor.selection.getDimensions(), @tooltip.offsetParent, @editor.root)
      @tooltipInput.focus()
    if value?
      @editor.selection.format('link', value, { source: 'user' })<commit_msg>retrieve/set link attribute value<commit_after>Scribe = require('../scribe')


enterEditMode = (url) ->
  url = 'https://' + url unless /^http[s]?:\/\//.test(url)
  @tooltipInput.value = url
  Scribe.DOM.addClass(@tooltip, 'editing')

exitEditMode = ->
  if @tooltipLink.innerText != @tooltipInput.value
    @tooltipLink.innerText = @tooltipLink.href = @tooltipInput.value
    @editor.setSelection(@savedRange, true)
    @editor.selection.format('link', @tooltipInput.value, { source: 'user' })
    @toolbar.emit(Scribe.Toolbar.events.FORMAT, 'link', @tooltipInput.value)
    @editor.setSelection(null, true)
  Scribe.DOM.removeClass(@tooltip, 'editing')

hideTooltip = ->
  @tooltip.style.left = '-10000px'

initListeners = ->
  @editor.root.addEventListener('click', (event) =>
    link = event.target
    while link? and link.tagName != 'DIV' and link.tagName != 'BODY'
      if link.tagName == 'A'
        start = new Scribe.Position(@editor, link, 0)
        end = new Scribe.Position(@editor, link, link.textContent.length)
        @savedRange = new Scribe.Range(@editor, start, end)
        @tooltipLink.innerText = @tooltipLink.href = link.href
        Scribe.DOM.removeClass(@tooltip, 'editing')
        showTooptip.call(this, link, @tooltip.offsetParent, @editor.root)
        return
      link = link.parentNode
    hideTooltip.call(this)
  )
  @button.addEventListener('click', =>
    value = null
    if Scribe.DOM.hasClass(@button, 'active')
      value = false
    else
      @savedRange = @editor.selection.getRange()
      enterEditMode.call(this, @savedRange.getText())
      Scribe.DOM.addClass(@tooltip, 'editing')
      showTooptip.call(this, @editor.selection.getDimensions(), @tooltip.offsetParent, @editor.root)
      @tooltipInput.focus()
    if value?
      @editor.selection.format('link', value, { source: 'user' })
{'fraction_non_alphanumeric': 0.15964590964590963, 'fraction_numerical': 0.003357753357753358, 'mean_word_length': 3.674750356633381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '2623975', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1045, 'n_words': 184}