fix mousewheel on scrollables.
This commit is contained in:
parent
5d67e189a8
commit
2cf1e5ee44
|
@ -942,15 +942,7 @@ function List(options) {
|
||||||
if (this.selectedBg === -1) this.selectedBg = exports.NORMAL;
|
if (this.selectedBg === -1) this.selectedBg = exports.NORMAL;
|
||||||
if (this.selectedFg === -1) this.selectedFg = exports.NORMAL;
|
if (this.selectedFg === -1) this.selectedFg = exports.NORMAL;
|
||||||
|
|
||||||
this.on('wheeldown', function(data) {
|
this.mouse = options.mouse || false;
|
||||||
self.select(self.selected + 2);
|
|
||||||
self.screen.render();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.on('wheelup', function(data) {
|
|
||||||
self.select(self.selected - 2);
|
|
||||||
self.screen.render();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (options.items) {
|
if (options.items) {
|
||||||
options.items.forEach(this.add.bind(this));
|
options.items.forEach(this.add.bind(this));
|
||||||
|
@ -981,10 +973,26 @@ List.prototype.add = function(item) {
|
||||||
this.append(item);
|
this.append(item);
|
||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
|
|
||||||
|
if (!this.mouse) return;
|
||||||
|
|
||||||
item.on('click', function(data) {
|
item.on('click', function(data) {
|
||||||
self.select(item);
|
self.select(item);
|
||||||
self.screen.render();
|
self.screen.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Temporary workaround:
|
||||||
|
// We cannot bind to clickable events on the list because the parent will
|
||||||
|
// receive *all* clickable events in that particular area of the screen.
|
||||||
|
// Possibly fix in the future by emitting events through tree traversal as
|
||||||
|
// well as bubbling events.
|
||||||
|
item.on('wheeldown', function(data) {
|
||||||
|
self.select(self.selected + 2);
|
||||||
|
self.screen.render();
|
||||||
|
});
|
||||||
|
item.on('wheelup', function(data) {
|
||||||
|
self.select(self.selected - 2);
|
||||||
|
self.screen.render();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
List.prototype._remove = List.prototype.remove;
|
List.prototype._remove = List.prototype.remove;
|
||||||
|
@ -1072,6 +1080,18 @@ List.prototype.down = function(offset) {
|
||||||
function ScrollableText(options) {
|
function ScrollableText(options) {
|
||||||
options.alwaysScroll = true;
|
options.alwaysScroll = true;
|
||||||
ScrollableBox.call(this, options);
|
ScrollableBox.call(this, options);
|
||||||
|
|
||||||
|
if (options.mouse) {
|
||||||
|
var self = this;
|
||||||
|
this.on('wheeldown', function(data) {
|
||||||
|
self.scroll(self.height / 2 | 0 || 1);
|
||||||
|
self.screen.render();
|
||||||
|
});
|
||||||
|
this.on('wheelup', function(data) {
|
||||||
|
self.scroll(-(self.height / 2 | 0) || -1);
|
||||||
|
self.screen.render();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollableText.prototype.__proto__ = ScrollableBox.prototype;
|
ScrollableText.prototype.__proto__ = ScrollableBox.prototype;
|
||||||
|
|
|
@ -66,6 +66,7 @@ screen.children[0].append(new blessed.Box({
|
||||||
var list = new blessed.List({
|
var list = new blessed.List({
|
||||||
screen: screen,
|
screen: screen,
|
||||||
parent: screen,
|
parent: screen,
|
||||||
|
mouse: true,
|
||||||
fg: 4,
|
fg: 4,
|
||||||
bg: -1,
|
bg: -1,
|
||||||
border: {
|
border: {
|
||||||
|
@ -140,6 +141,7 @@ var lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do ei
|
||||||
var stext = new blessed.ScrollableText({
|
var stext = new blessed.ScrollableText({
|
||||||
screen: screen,
|
screen: screen,
|
||||||
parent: screen,
|
parent: screen,
|
||||||
|
mouse: true,
|
||||||
content: lorem,
|
content: lorem,
|
||||||
fg: 4,
|
fg: 4,
|
||||||
bg: -1,
|
bg: -1,
|
||||||
|
|
Loading…
Reference in New Issue