Skip to content

Commit

Permalink
feat: reuse domStylesReader between editors
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 11, 2021
1 parent 7fb05bd commit a605d57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Minimap from './minimap'
import config from './config.json'
import * as PluginManagement from './plugin-management'
import { treeSitterWarning } from './performance-monitor'
import DOMStylesReader from './dom-styles-reader'

export { default as config } from './config.json'
export * from './plugin-management'
Expand Down Expand Up @@ -63,6 +64,12 @@ let subscriptionsOfCommands = null
*/
export const emitter = new Emitter()


/**
DOMStylesReader cache used for storing token colors
*/
let DOMStylesReaderInstance = null

/**
* Activates the minimap package.
*/
Expand All @@ -85,6 +92,8 @@ export function activate () {
})

editorsMinimaps = new Map()
DOMStylesReaderInstance = new DOMStylesReader()

subscriptions = new CompositeDisposable()
active = true

Expand All @@ -100,6 +109,8 @@ export function activate () {
export function minimapViewProvider (model) {
if (model instanceof Minimap) {
const element = new MinimapElement()
// add DOMStylesReaderInstance
element.DOMStylesReader = DOMStylesReaderInstance;
element.setModel(model)
return element
}
Expand All @@ -125,6 +136,7 @@ export function deactivate () {
subscriptionsOfCommands.dispose()
subscriptionsOfCommands = null
editorsMinimaps = undefined
DOMStylesReaderInstance.invalidateDOMStylesCache()
toggled = false
active = false
}
Expand Down Expand Up @@ -153,6 +165,7 @@ export function toggle () {
toggled = true
initSubscriptions()
}
DOMStylesReaderInstance.invalidateDOMStylesCache()
}

/**
Expand Down
6 changes: 0 additions & 6 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Mixin from 'mixto'

import * as Main from '../main'
import CanvasLayer from '../canvas-layer'
import DOMStylesReader from '../dom-styles-reader'

const SPEC_MODE = atom.inSpecMode()

Expand Down Expand Up @@ -76,11 +75,6 @@ export default class CanvasDrawer extends Mixin {

// the maximum number of tokens to render in one line
this.maxTokensInOneLine = atom.config.get('minimap.maxTokensInOneLine')

/**
* This MinimapElement's DOMStylesReader
*/
this.DOMStylesReader = new DOMStylesReader()
}

/**
Expand Down

0 comments on commit a605d57

Please sign in to comment.