Skip to content

Commit

Permalink
Implement configurable minimap redraw delay
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Mar 23, 2017
1 parent 07e65ed commit c1ec247
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ class Minimap {
* @access private
*/
this.configDevicePixelRatioRounding = null
/**
* A number of milliseconds which determines how often the minimap should redraw itself after
* detecting changes in the text editor. A value of 0 will cause the minimap to redraw
* immediately.
*
* @type {number}
* @access private
*/
this.redrawDelay = 0
/**
* A boolean value to store whether this Minimap have been destroyed or not.
*
Expand Down Expand Up @@ -305,10 +314,15 @@ class Minimap {
scheduleChanges (changes) {
this.pendingChangeEvents.push(...changes)

// If any changes happened within the timeout's delay, a timeout will already have been
// scheduled -> no need to schedule again
// Optimisation: If the redraw delay is set to 0, do not even schedule a timer
if (!this.redrawDelay) {
return this.flushChanges()
}

if (!this.flushChangesTimer) {
this.flushChangesTimer = setTimeout(() => { this.flushChanges() }, 1000)
// If any changes happened within the timeout's delay, a timeout will already have been
// scheduled -> no need to schedule again
this.flushChangesTimer = setTimeout(() => { this.flushChanges() }, this.redrawDelay)
}
}

Expand Down Expand Up @@ -455,6 +469,9 @@ class Minimap {
subs.add(atom.config.observe('minimap.scrollSensitivity', opts, (scrollSensitivity) => {
this.scrollSensitivity = scrollSensitivity
}))
subs.add(atom.config.observe('minimap.redrawDelay', opts, (redrawDelay) => {
this.redrawDelay = redrawDelay
}))
// cdprr is shorthand for configDevicePixelRatioRounding
subs.add(atom.config.observe(
'minimap.devicePixelRatioRounding',
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
"type": "boolean",
"default": true
},
"redrawDelay": {
"type": "number",
"default": 0,
"minimum": 0,
"maximum": 1000,
"description": "Controls how often (in ms) the minimap should redraw itself after changing the text editor's contents. Setting this to 100ms or higher could dramatically improve editor responsiveness when working with large files. A value of 0 will cause the minimap to redraw itself immediately on each change."
},
"adjustMinimapWidthToSoftWrap": {
"type": "boolean",
"default": true,
Expand Down

0 comments on commit c1ec247

Please sign in to comment.