Add scroll_to_bottom method for TextAreaView (StringWidget).

This commit is contained in:
Jonathan Frederic 2013-11-19 08:19:28 -08:00 committed by Jonathan Frederic
parent 9019b639d1
commit d795654251
2 changed files with 14 additions and 1 deletions

View File

@ -63,6 +63,14 @@ define(["notebook/js/widget"], function(widget_manager){
this.$textbox.val(this.model.get('value'));
}
if (this.last_scroll_to_bottom == undefined) {
this.last_scroll_to_bottom = 0;
}
if (this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms')) {
this.last_scroll_to_bottom < this.model.get('scroll_to_bottoms');
this.$textbox.scrollTop(this.$textbox[0].scrollHeight);
}
var disabled = this.model.get('disabled');
this.$textbox.prop('disabled', disabled);

View File

@ -27,11 +27,12 @@ class StringWidget(Widget):
default_view_name = Unicode('TextBoxView')
# Keys
_keys = ['value', 'disabled', 'description', 'submits']
_keys = ['value', 'disabled', 'description', 'submits', 'scroll_to_bottoms']
value = Unicode(help="String value")
disabled = Bool(False, help="Enable or disable user changes")
description = Unicode(help="Description of the value this widget represents")
submits = Int(0, help="Used to capture and fire submission ")
scroll_to_bottoms = Int(0, help="Used to scroll a TextAreaView to the bottom")
def __init__(self, **kwargs):
@ -39,6 +40,10 @@ class StringWidget(Widget):
self._submission_callbacks = []
def scroll_to_bottom(self):
self.scroll_to_bottoms += 1
def on_submit(self, callback, remove=False):
"""Register a callback to handle text submission (triggered when the
user clicks enter).