Throttles selection match finding, render throttling now configurable

This commit is contained in:
Dan Kaplun 2015-01-03 08:11:44 -06:00
parent 3c075a9456
commit 04b337ccd9
3 changed files with 17 additions and 9 deletions

View File

@ -7,6 +7,7 @@ var fs = Promise.promisifyAll(require('fs'));
var extname = require('path').extname;
var chardet = Promise.promisifyAll(require('chardet'));
var iconv = require('iconv-lite');
var lodash = require('lodash');
var Slap = require('./Slap');
var BaseElement = require('./BaseElement');
@ -791,7 +792,7 @@ Editor.prototype._initHandlers = function () {
});
['cursor', 'startSelection'].forEach(function (evt) {
self.on(evt, function () {
self.on(evt, lodash.throttle(function () {
if (self.screen.focused === self) {
var selection = self.select();
var line = self.line(selection.end.y);
@ -804,7 +805,7 @@ Editor.prototype._initHandlers = function () {
: [];
self.screen.render();
}
});
}, self.options.perf.matchesRenderThrottle));
});
self.on('path', function (path) { self.language(extname(path).slice(1)); });

View File

@ -32,6 +32,10 @@ function Slap (opts) {
self.fileBrowser.focus();
self.toggleInsertMode();
self.render = lodash.throttle(function () {
return blessed.Screen.prototype.render.apply(self, arguments);
}, self.options.perf.renderThrottle);
}
Slap.prototype.__proto__ = blessed.Screen.prototype;
Slap.global = null;
@ -205,10 +209,6 @@ Slap.prototype._initHandlers = function () {
return BaseElement.prototype._initHandlers.apply(self, arguments);
};
Slap.prototype.render = lodash.throttle(function () {
return blessed.Screen.prototype.render.apply(this, arguments);
}, 33);
module.exports = Slap;
// circular imports

View File

@ -42,9 +42,6 @@ bottom = 0
[logger]
level = "info"
[perf]
profile = false
;;;;;;;;;;;;
; Bindings ;
;;;;;;;;;;;;
@ -260,3 +257,13 @@ bg = "yellow"
[button.danger.style.hover]
bg = "red"
;;;;;;;;;;;;;;;;;;;;;;
; Performance tweaks ;
;;;;;;;;;;;;;;;;;;;;;;
[perf]
profile = false
renderThrottle = 50
[editor.perf]
matchesRenderThrottle = 150