Skip to content

Commit

Permalink
Merge pull request ajaxorg#1507 from ajaxorg/scroll_past_end
Browse files Browse the repository at this point in the history
[WIP] scrollPastEnd
  • Loading branch information
Ruben Daniels committed Jul 7, 2013
2 parents 5585535 + 1ad2602 commit a25a685
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ bindCheckbox("fade_fold_widgets", function(checked) {
bindCheckbox("read_only", function(checked) {
env.editor.setReadOnly(checked);
});
bindCheckbox("scrollPastEnd", function(checked) {
env.editor.setOption("scrollPastEnd", checked);
});

bindDropdown("split", function(value) {
var sp = env.split;
Expand Down
8 changes: 8 additions & 0 deletions kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@
<input type="checkbox" id="read_only">
</td>
</tr>
<tr>
<td >
<label for="scrollPastEnd">Scroll Past End</label>
</td>
<td>
<input type="checkbox" id="scrollPastEnd" checked>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Edit Snippets" onclick="env.editSnippets()">
Expand Down
1 change: 1 addition & 0 deletions lib/ace/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ config.defineOptions(Editor.prototype, "editor", {
fontFamily: "renderer",
maxLines: "renderer",
minLines: "renderer",
scrollPastEnd: "renderer",

scrollSpeed: "$mouseHandler",
dragDelay: "$mouseHandler",
Expand Down
29 changes: 26 additions & 3 deletions lib/ace/virtual_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ var VirtualRenderer = function(container, theme) {

var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
var screenLines = this.session.getScreenLength()
var maxHeight = screenLines * this.lineHeight;
var maxHeight = screenLines * this.lineHeight;

var offset = this.scrollTop % this.lineHeight;
var minHeight = this.$size.scrollerHeight + this.lineHeight;
Expand All @@ -864,6 +864,14 @@ var VirtualRenderer = function(container, theme) {
this.scrollBarH.setVisible(horizScroll);
}

if (!this.$maxLines && this.$scrollPastEnd) {
if (this.scrollTop > maxHeight - this.$size.scrollerHeight)
maxHeight += Math.min(
(this.$size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd,
this.scrollTop - maxHeight + this.$size.scrollerHeight
);
}

var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
this.$size.scrollerHeight - maxHeight < 0);
var vScrollChanged = this.$vScroll !== vScroll;
Expand Down Expand Up @@ -1268,7 +1276,8 @@ var VirtualRenderer = function(container, theme) {
if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top)
return true;
if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
- this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
- this.layerConfig.maxHeight - (this.$size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd
< -1 + this.scrollMargin.bottom)
return true;
// todo: better handle horizontal scrolling
if (deltaX)
Expand Down Expand Up @@ -1579,9 +1588,23 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
}
},
minLines: {
set: function(name) {
set: function(val) {
this.updateFull();
}
},
scrollPastEnd: {
set: function(val) {
if (val == true)
val = 1;
else if (val == false)
val = 0;
if (this.$scrollPastEnd == val)
return;
this.$scrollPastEnd = val;
this.$loop.schedule(this.CHANGE_SCROLL);
},
initialValue: 1,
handlesSet: true
}
});

Expand Down

0 comments on commit a25a685

Please sign in to comment.