lib/multi-wrap-guide-view.js
// Sets up wrap guide event and command handlers.
Sets up wrap guide event and command handlers.
Sets up wrap guide event and command handlers .
handleEvents () {
    const redrawCallback = () => this.redraw()
    this.subs.add(atom.config.onDidChange('editor.fontSize', () => {
      setTimeout(redrawCallback, 0)
    }))
    this.subs.add(this.editorElement.onDidAttach(() => {
      this.scrollView = this.editorElement.querySelector('.scroll-view')
      this.scrollView.append(this.element)
      redrawCallback()
    }))
    this.subs.add(this.editorElement.onDidChangeScrollLeft(() => redrawCallback()))
    this.subs.add(this.editorElement.onDidChangeScrollTop(() => redrawCallback()))
    this.subs.add(this.editor.onDidChangePath(() => redrawCallback()))
    this.subs.add(this.editor.onDidChangeSoftWrapped(() => redrawCallback()))
    this.subs.add(this.editor.onDidChangeGrammar(() => {
      this.columns = this.getColumns()
      this.rows = this.getRows()
      redrawCallback()
    }))
    const gutter = this.editorElement.querySelector('.gutter')
    if (gutter) {
      gutter.onclick = event => {
        if (event.target.className === 'icon-right') {
          redrawCallback()
        }
        return true
      }
    }
    this.subs.add(atom.commands.add('atom-text-editor', {
      'editor:fold-all': () => redrawCallback(),
      'editor:unfold-all': () => redrawCallback(),
      'editor:fold-current-row': () => redrawCallback(),
      'editor:unfold-current-row': () => redrawCallback(),
      'editor:fold-selection': () => redrawCallback(),
      'editor:fold-at-indent-level-1': () => redrawCallback(),
      'editor:fold-at-indent-level-2': () => redrawCallback(),
      'editor:fold-at-indent-level-3': () => redrawCallback(),
      'editor:fold-at-indent-level-4': () => redrawCallback(),
      'editor:fold-at-indent-level-5': () => redrawCallback(),
      'editor:fold-at-indent-level-6': () => redrawCallback(),
      'editor:fold-at-indent-level-7': () => redrawCallback(),
      'editor:fold-at-indent-level-8': () => redrawCallback(),
      'editor:fold-at-indent-level-9': () => redrawCallback()
    }))
    const mousemoveHandler = e => {
      const [col, row] = Array.from(this.positionFromMouseEvent(e))
      this.currentCursorColumn = col
      this.currentCursorRow = row
    }
    this.editorElement.addEventListener('mousemove', mousemoveHandler)
    this.subs.add(new Disposable(() =>
      this.editorElement.removeEventListener('mousemove', mousemoveHandler)
    ))
    this.subs.add(atom.commands.add('atom-workspace', {
      'multi-wrap-guide:create-vertical-guide': {
        didDispatch: () => this.createVerticalGuide(this.currentCursorColumn),
        hiddenInCommandPalette: true
      },
      'multi-wrap-guide:create-horizontal-guide': {
        didDispatch: () => this.createHorizontalGuide(this.currentCursorRow),
        hiddenInCommandPalette: true
      },
      'multi-wrap-guide:remove-guide': {
        didDispatch: () => this.removeGuide(this.currentCursorRow, this.currentCursorColumn),
        hiddenInCommandPalette: true
      },
      'multi-wrap-guide:line-break': {
        didDispatch: () => this.lineBreak(this.currentCursorColumn),
        hiddenInCommandPalette: true
      }
    }))
    this.emitter.on('did-toggle-lock', () => {
      if (atom.config.get('multi-wrap-guide.locked')) {
        this.lock()
      } else {
        this.unlock()
      }
      this.redraw()
    })
    this.emitter.on('did-toggle', () => {
      atom.config.set('multi-wrap-guide.enabled', !atom.config.get('multi-wrap-guide.enabled'))
      this.redraw()
    })
    this.emitter.on('did-change-guides', data => {
      const { rows, columns, scope } = data
      if (`${this.editor.getRootScopeDescriptor()}` !== `${scope}`) return
      [this.rows, this.columns] = Array.from([rows, columns])
      this.redraw()
    })
    this.emitter.on('make-default', () => {
      if (this.editor !== atom.workspace.getActiveTextEditor()) return
      this.saveColumns(null)
      this.saveRows(null)
    })
    this.emitter.on('make-scope', () => {
      if (this.editor !== atom.workspace.getActiveTextEditor()) return
      const scopeSelector = getRootScopeSelector(this.editor)
      this.saveColumns(scopeSelector)
      this.saveRows(scopeSelector)
    })
  }
handleEvents ( ) { const redrawCallback = ( ) => this . redraw ( ) this . subs . add ( atom . config . onDidChange ( 'editor.fontSize' , ( ) => { setTimeout ( redrawCallback , 0 ) } ) ) this . subs . add ( this . editorElement . onDidAttach ( ( ) => { this . scrollView = this . editorElement . querySelector ( '.scroll-view' ) this . scrollView . append ( this . element ) redrawCallback ( ) } ) ) this . subs . add ( this . editorElement . onDidChangeScrollLeft ( ( ) => redrawCallback ( ) ) ) this . subs . add ( this . editorElement . onDidChangeScrollTop ( ( ) => redrawCallback ( ) ) ) this . subs . add ( this . editor . onDidChangePath ( ( ) => redrawCallback ( ) ) ) this . subs . add ( this . editor . onDidChangeSoftWrapped ( ( ) => redrawCallback ( ) ) ) this . subs . add ( this . editor . onDidChangeGrammar ( ( ) => { this . columns = this . getColumns ( ) this . rows = this . getRows ( ) redrawCallback ( ) } ) ) const gutter = this . editorElement . querySelector ( '.gutter' ) if ( gutter ) { gutter . onclick = event => { if ( event . target . className === 'icon-right' ) { redrawCallback ( ) } return true } } this . subs . add ( atom . commands . add ( 'atom-text-editor' , { 'editor:fold-all' : ( ) => redrawCallback ( ) , 'editor:unfold-all' : ( ) => redrawCallback ( ) , 'editor:fold-current-row' : ( ) => redrawCallback ( ) , 'editor:unfold-current-row' : ( ) => redrawCallback ( ) , 'editor:fold-selection' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-1' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-2' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-3' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-4' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-5' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-6' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-7' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-8' : ( ) => redrawCallback ( ) , 'editor:fold-at-indent-level-9' : ( ) => redrawCallback ( ) } ) ) const mousemoveHandler = e => { const [ col , row ] = Array . from ( this . positionFromMouseEvent ( e ) ) this . currentCursorColumn = col this . currentCursorRow = row } this . editorElement . addEventListener ( 'mousemove' , mousemoveHandler ) this . subs . add ( new Disposable ( ( ) => this . editorElement . removeEventListener ( 'mousemove' , mousemoveHandler ) ) ) this . subs . add ( atom . commands . add ( 'atom-workspace' , { 'multi-wrap-guide:create-vertical-guide' : { didDispatch : ( ) => this . createVerticalGuide ( this . currentCursorColumn ) , hiddenInCommandPalette : true } , 'multi-wrap-guide:create-horizontal-guide' : { didDispatch : ( ) => this . createHorizontalGuide ( this . currentCursorRow ) , hiddenInCommandPalette : true } , 'multi-wrap-guide:remove-guide' : { didDispatch : ( ) => this . removeGuide ( this . currentCursorRow , this . currentCursorColumn ) , hiddenInCommandPalette : true } , 'multi-wrap-guide:line-break' : { didDispatch : ( ) => this . lineBreak ( this . currentCursorColumn ) , hiddenInCommandPalette : true } } ) ) this . emitter . on ( 'did-toggle-lock' , ( ) => { if ( atom . config . get ( 'multi-wrap-guide.locked' ) ) { this . lock ( ) } else { this . unlock ( ) } this . redraw ( ) } ) this . emitter . on ( 'did-toggle' , ( ) => { atom . config . set ( 'multi-wrap-guide.enabled' , ! atom . config . get ( 'multi-wrap-guide.enabled' ) ) this . redraw ( ) } ) this . emitter . on ( 'did-change-guides' , data => { const { rows , columns , scope } = data if ( ` ${ this . editor . getRootScopeDescriptor ( ) } ` !== ` ${ scope } ` ) return [ this . rows , this . columns ] = Array . from ( [ rows , columns ] ) this . redraw ( ) } ) this . emitter . on ( 'make-default' , ( ) => { if ( this . editor !== atom . workspace . getActiveTextEditor ( ) ) return this . saveColumns ( null ) this . saveRows ( null ) } ) this . emitter . on ( 'make-scope' , ( ) => { if ( this . editor !== atom . workspace . getActiveTextEditor ( ) ) return const scopeSelector = getRootScopeSelector ( this . editor ) this . saveColumns ( scopeSelector ) this . saveRows ( scopeSelector ) } ) }
Sets up wrap guide event and command handlers.
Sets up wrap guide event and command handlers .
// respond to editor events // setTimeout() to wait for editorElement.getDefaultCharacterWidth() measurement to happen // respond to code folding events // respond to mouse move event to keep track of current row, col position // respond to multi-wrap-guide commands // respond to multi-wrap-guide events // guide columns are specific to grammars, so only update for the current scope