fix #2495 editor freezes when setting scrollmargin and maxLines together
This commit is contained in:
parent
ad5802be06
commit
0db985a3d7
2 changed files with 42 additions and 11 deletions
|
|
@ -968,14 +968,15 @@ var VirtualRenderer = function(container, theme) {
|
|||
: 0;
|
||||
maxHeight += scrollPastEnd;
|
||||
|
||||
this.session.setScrollTop(Math.max(-this.scrollMargin.top,
|
||||
Math.min(this.scrollTop, maxHeight - size.scrollerHeight + this.scrollMargin.bottom)));
|
||||
var sm = this.scrollMargin;
|
||||
this.session.setScrollTop(Math.max(-sm.top,
|
||||
Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom)));
|
||||
|
||||
this.session.setScrollLeft(Math.max(-this.scrollMargin.left, Math.min(this.scrollLeft,
|
||||
longestLine + 2 * this.$padding - size.scrollerWidth + this.scrollMargin.right)));
|
||||
this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft,
|
||||
longestLine + 2 * this.$padding - size.scrollerWidth + sm.right)));
|
||||
|
||||
var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
|
||||
size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop);
|
||||
size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top);
|
||||
var vScrollChanged = this.$vScroll !== vScroll;
|
||||
if (vScrollChanged) {
|
||||
this.$vScroll = vScroll;
|
||||
|
|
|
|||
|
|
@ -36,26 +36,40 @@ if (typeof process !== "undefined") {
|
|||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Editor = require("./edit_session").Editor;
|
||||
var EditSession = require("./edit_session").EditSession;
|
||||
var VirtualRenderer = require("./virtual_renderer").VirtualRenderer;
|
||||
var assert = require("./test/assertions");
|
||||
|
||||
var editor = null;
|
||||
module.exports = {
|
||||
"test: screen2text the column should be rounded to the next character edge" : function() {
|
||||
setUp: function() {
|
||||
if (editor)
|
||||
editor.destroy()
|
||||
var el = document.createElement("div");
|
||||
|
||||
if (!el.getBoundingClientRect) {
|
||||
console.log("Skipping test: This test only runs in the browser");
|
||||
return;
|
||||
}
|
||||
|
||||
el.style.left = "20px";
|
||||
el.style.top = "30px";
|
||||
el.style.width = "300px";
|
||||
el.style.height = "100px";
|
||||
document.body.appendChild(el);
|
||||
|
||||
var renderer = new VirtualRenderer(el);
|
||||
var editor = new Editor(renderer);
|
||||
editor.on("destroy", function() {
|
||||
document.body.removeChild(el);
|
||||
});
|
||||
},
|
||||
tearDown: function() {
|
||||
editor && editor.destroy();
|
||||
editor = null;
|
||||
},
|
||||
"test: screen2text the column should be rounded to the next character edge" : function() {
|
||||
if (!editor) return;
|
||||
var renderer = editor.renderer;
|
||||
|
||||
renderer.setPadding(0);
|
||||
renderer.setSession(new EditSession("1234"));
|
||||
|
||||
|
|
@ -72,8 +86,24 @@ module.exports = {
|
|||
testPixelToText(9, 0, 0, 1);
|
||||
testPixelToText(10, 0, 0, 1);
|
||||
testPixelToText(14, 0, 0, 1);
|
||||
testPixelToText(15, 0, 0, 2);
|
||||
document.body.removeChild(el);
|
||||
testPixelToText(15, 0, 0, 2);
|
||||
},
|
||||
|
||||
"test scrollmargin + autosize": function(done) {
|
||||
var editor = initAce();
|
||||
if (!editor) return;
|
||||
editor.setOptions({
|
||||
maxLines: 100,
|
||||
useWrapMode: true
|
||||
});
|
||||
editor.renderer.setScrollMargin(10, 10);
|
||||
editor.setValue("\n\n");
|
||||
editor.setValue("\n\n\n\n");
|
||||
editor.renderer.once("afterRender", function() {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
// change tab size after setDocument (for text layer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue