<commit_before>'use strict'
{CompositeDisposable} = require 'atom'
_ = require 'underscore'

class BlockCursor
  cursorStyle = null
  cursorTypeMap =
    '\u25AE - Block': 'block'
    '\u25AF - Bordered box': 'bordered-box'
    '| - I-beam': 'i-beam'
    '_ - Underline': 'underline'
  primarySelector = 'atom-text-editor::shadow .cursors .cursor'
  secondarySelector = 'atom-text-editor::shadow .cursors.blink-off .cursor'

  config:
    cursorType:
      type: 'string'
      default: '\u25AE - Block'
      enum: (key for own key of cursorTypeMap)
    primaryColor:
      description: 'Primary color of the cursor'
      type: 'color'
      default: '#393939'
    secondaryColor:
      description: 'Secondary color of the cursor'
      type: 'color'
      default: 'transparent'
    blinkInterval:
      description: 'Interval of the cursor blink - the period between primaryColor and secondaryColor - in milliseconds. Set to 0 to disable blinking.'
      type: 'integer'
      default: 400
      minimum: 0
    pulseDuration:
      description: 'Duration of the pulse transition in milliseconds, set to 0 to disable pulse'
      type: 'integer'
      default: 0
      minimum: 0
    cursorThickness:
      description: 'Thickness of the cursor in pixels. Doesn\'t apply to "block" cursor type'
      type: 'integer'
      default: 1
      minimum: 1
    zzzpreview:
      title: 'Preview'
      description: 'This field does nothing, it\'s just here to preview your cursor'
      type: 'string'
      default: ''

  activate: ->
    @subs = new CompositeDisposable()
    @subs.add atom.config.observe 'block-cursor.cursorType', @applyCursorType.bind @
    @subs.add atom.config.observe 'block-cursor.primaryColor', @applyPrimaryColor.bind @
    @subs.add atom.config.observe 'block-cursor.secondaryColor', @applySecondaryColor.bind @
    @subs.add atom.config.observe 'block-cursor.blinkInterval', @applyBlinkInterval.bind @
    @subs.add atom.config.observe 'block-cursor.pulseDuration', @applyPulseDuration.bind @
    @subs.add atom.config.observe 'block-cursor.cursorThickness', @applyCursorThickness.bind @
    atom.config.set 'block-cursor.zzzpreview', 'The quick brown fox jumps over the lazy dog'
    @editorSub = null

  deactivate: ->
    @subs.dispose()
    @editorSub?.dispose?()
    if cursorStyle?
      cursorStyle.parentNode.removeChild cursorStyle
      cursorStyle = null

  applyCursorType: (cursorTypeName) ->
    cursorType = cursorTypeMap[cursorTypeName]
    workspaceView = atom.views.getView atom.workspace
    workspaceView.className = workspaceView.className.replace /block-cursor-(block|bordered-box|i-beam|underline)/, ''
    workspaceView.classList.add "block-cursor-#{cursorType}"

  applyPrimaryColor: (color) ->
    color = color.toRGBAString?() or @toRGBAString color
    @updateStylesheet primarySelector, 'background-color', color
    @updateStylesheet primarySelector, 'border-color', color

  applySecondaryColor: (color) ->
    color = color.toRGBAString?() or @toRGBAString color
    @updateStylesheet secondarySelector, 'background-color', color
    @updateStylesheet secondarySelector, 'border-color', color

  applyBlinkInterval: (interval) ->
    @editorSub?.dispose?()
    @editorSub = atom.workspace.observeTextEditors (editor) ->
      editorPresenter = atom.views.getView(editor).component.presenter
      editorPresenter.cursorBlinkPeriod = interval * 2
      editorPresenter.stopBlinkingCursors(true)
      if interval > 0
        editorPresenter.startBlinkingCursorsAfterDelay = do ->
          _.debounce(editorPresenter.startBlinkingCursors, editorPresenter.getCursorBlinkResumeDelay())
      else
        atom.config.set 'block-cursor.secondaryColor', atom.config.get 'block-cursor.primaryColor'
        editorPresenter.startBlinkingCursorsAfterDelay = ->

  applyPulseDuration: (duration) ->
    @updateStylesheet primarySelector, 'transition-duration', "#{duration}ms"

  applyCursorThickness: (thickness) ->
    @updateStylesheet primarySelector, 'border-width', "#{thickness}px"

  getCursorStyle: ->
    return cursorStyle if cursorStyle?
    cursorStyle = document.createElement 'style'
    cursorStyle.type = 'text/css'
    document.querySelector('head atom-styles').appendChild cursorStyle
    cursorStyle

  updateStylesheet: (selector, property, value) ->
    sheet = @getCursorStyle().sheet
    sheet.insertRule "#{selector} { #{property}: #{value}; }", sheet.cssRules.length

  toRGBAString: (color) ->
    return color if typeof color is 'string'
    return unless color.red and color.green and color.blue and color.alpha
    "rgba(#{color.red}, #{color.green}, #{color.blue}, #{color.alpha})"

module.exports = new BlockCursor()<commit_msg>rewritten some parts<commit_after>'use strict'
{CompositeDisposable} = require 'atom'

class BlockCursor
  cursorStyle = null
  cursorTypeMap =
    '\u25AE - Block': 'block'
    '\u25AF - Bordered box': 'bordered-box'
    '| - I-beam': 'i-beam'
    '_ - Underline': 'underline'
  primarySelector = 'atom-text-editor::shadow .cursors .cursor'
  secondarySelector = 'atom-text-editor::shadow .cursors.blink-off .cursor'

  config:
    cursorType:
      type: 'string'
      default: '\u25AE - Block'
      enum: (key for own key of cursorTypeMap)
    primaryColor:
      description: 'Primary color of the cursor'
      type: 'color'
      default: '#393939'
    secondaryColor:
      description: 'Secondary color of the cursor'
      type: 'color'
      default: 'transparent'
    blinkInterval:
      description: 'Cursor blinking interval in milliseconds. Set to 0 to disable blinking. Doesn\'t work for mini editors, except for disabling cursor blinking'
      type: 'integer'
      default: 800
      minimum: 0
    pulseDuration:
      description: 'Duration of the pulse transition in milliseconds, set to 0 to disable pulse'
      type: 'integer'
      default: 0
      minimum: 0
    cursorThickness:
      description: 'Thickness of the cursor in pixels. Doesn\'t apply to "block" cursor type'
      type: 'integer'
      default: 1
      minimum: 1
    zzzpreview:
      title: 'Preview'
      description: 'This field does nothing, it\'s just here to preview your cursor'
      type: 'string'
      default: ''

  activate: ->
    @subs = new CompositeDisposable()
    @subs.add [
      atom.config.observe 'block-cursor.cursorType', @applyCursorType
      atom.config.observe 'block-cursor.primaryColor', @applyPrimaryColor
      atom.config.observe 'block-cursor.secondaryColor', @applySecondaryColor
      atom.config.observe 'block-cursor.blinkInterval', @applyBlinkInterval.bind @
      atom.config.observe 'block-cursor.pulseDuration', @applyPulseDuration
      atom.config.observe 'block-cursor.cursorThickness', @applyCursorThickness
    ]
    atom.config.set 'block-cursor.zzzpreview', 'The quick brown fox jumps over the lazy dog'

  deactivate: ->
    @subs.dispose()
    if cursorStyle?
      cursorStyle.parentNode.removeChild cursorStyle
      cursorStyle = null

  applyCursorType: (cursorTypeName) =>
    cursorType = cursorTypeMap[cursorTypeName]
    workspaceView = atom.views.getView atom.workspace
    workspaceView.className = workspaceView.className.replace /block-cursor-(block|bordered-box|i-beam|underline)/, ''
    workspaceView.className += " block-cursor-#{cursorType}"

  applyPrimaryColor: (color) =>
    color = color.toRGBAString?() or @toRGBAString color
    @updateStylesheet primarySelector, 'background-color', color
    @updateStylesheet primarySelector, 'border-color', color

  applySecondaryColor: (color) =>
    color = color.toRGBAString?() or @toRGBAString color
    @updateStylesheet secondarySelector, 'background-color', color
    @updateStylesheet secondarySelector, 'border-color', color

  applyBlinkInterval: do ->
    sub = null

    (interval) ->
      sub?.dispose?()
      sub = atom.workspace.observeTextEditors (editor) ->
        editorPresenter = atom.views.getView(editor).component.presenter
        editorPresenter.stopBlinkingCursors true
        if interval > 0
          editorPresenter.cursorBlinkPeriod = interval
          atom.config.set 'block-cursor.secondaryColor', 'transparent'
        else
          editorPresenter.cursorBlinkPeriod = -1 + Math.pow 2, 31
          atom.config.set 'block-cursor.secondaryColor', atom.config.get 'block-cursor.primaryColor'
        editorPresenter.startBlinkingCursors()
      @subs.add sub

  applyPulseDuration: (duration) =>
    @updateStylesheet primarySelector, 'transition-duration', "#{duration}ms"

  applyCursorThickness: (thickness) =>
    @updateStylesheet primarySelector, 'border-width', "#{thickness}px"

  getCursorStyle: ->
    return cursorStyle if cursorStyle?
    cursorStyle = document.createElement 'style'
    cursorStyle.type = 'text/css'
    document.querySelector('head atom-styles').appendChild cursorStyle
    cursorStyle

  updateStylesheet: (selector, property, value) ->
    sheet = @getCursorStyle().sheet
    sheet.insertRule "#{selector} { #{property}: #{value}; }", sheet.cssRules.length

  toRGBAString: (color) ->
    return color if typeof color is 'string'
    return unless color.red and color.green and color.blue and color.alpha
    "rgba(#{color.red}, #{color.green}, #{color.blue}, #{color.alpha})"

module.exports = new BlockCursor()
{'fraction_non_alphanumeric': 0.11057382333978079, 'fraction_numerical': 0.00548033526756931, 'mean_word_length': 3.5824716888232397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '81948', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2673, 'n_words': 666}