Skip to content

Commit 5acea6d

Browse files
authored
fix(VirtualRenderer): fix scrollbar overlap on autocompletion (#5713)
1 parent 09a0c5a commit 5acea6d

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

src/autocomplete_test.js

+61
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,67 @@ module.exports = {
15991599
var editor = initEditor("");
16001600
var completer = Autocomplete.for(editor);
16011601
assert.equal(Autocomplete.$sharedInstance == undefined, false);
1602+
},
1603+
"test: changing completion should render scrollbars correctly": function (done) {
1604+
var editor = initEditor("document");
1605+
var newLineCharacter = editor.session.doc.getNewLineCharacter();
1606+
var initialCompletions = [
1607+
{
1608+
caption: "small",
1609+
meta: "small",
1610+
value: "small"
1611+
}
1612+
];
1613+
var longCompletions = Array(10)
1614+
.fill(null)
1615+
.map((_, i) => ({
1616+
caption: `this is a really long string that I want to use for testing horizontal scroll ${i}`,
1617+
meta: `meta ${i}`,
1618+
value: `value ${i}`
1619+
}));
1620+
1621+
var currentCompletions = initialCompletions;
1622+
1623+
editor.completers = [
1624+
{
1625+
getCompletions: function (editor, session, pos, prefix, callback) {
1626+
var completions = currentCompletions;
1627+
callback(null, completions);
1628+
},
1629+
triggerCharacters: [newLineCharacter]
1630+
}
1631+
];
1632+
1633+
editor.moveCursorTo(0, 8);
1634+
user.type("Return"); // Accept suggestion
1635+
var popup = editor.completer.popup;
1636+
check(function () {
1637+
assert.equal(popup.data.length, 1);
1638+
assert.notOk(popup.renderer.scrollBar.isVisible);
1639+
user.type("Return"); // Accept suggestion
1640+
assert.equal(editor.getValue(), `document${newLineCharacter}small`);
1641+
// change completion values
1642+
currentCompletions = longCompletions;
1643+
check(function () {
1644+
user.type("Return"); // Enter new line
1645+
assert.equal(popup.renderer.layerConfig.height, popup.renderer.lineHeight * 1);
1646+
assert.equal(popup.data.length, 10);
1647+
check(function () {
1648+
assert.ok(popup.renderer.scrollBar.isVisible);
1649+
assert.equal(popup.renderer.layerConfig.height, popup.renderer.lineHeight * 8);
1650+
user.type("Return"); // Accept suggestion
1651+
assert.equal(editor.getValue(), `document${newLineCharacter}small${newLineCharacter}value 0`);
1652+
done();
1653+
});
1654+
});
1655+
});
1656+
function check(callback) {
1657+
popup = editor.completer.popup;
1658+
popup.renderer.on("afterRender", function wait() {
1659+
popup.renderer.off("afterRender", wait);
1660+
callback();
1661+
});
1662+
}
16021663
}
16031664
};
16041665

src/virtual_renderer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,11 @@ class VirtualRenderer {
11091109
}
11101110
var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine
11111111
// autoresize only after updating hscroll to include scrollbar height in desired height
1112-
if (this.$maxLines && this.lineHeight > 1)
1112+
if (this.$maxLines && this.lineHeight > 1){
11131113
this.$autosize();
1114+
// recalculate this after $autosize so we take vertical scroll into account when calculating width
1115+
hideScrollbars = size.height <= 2 * this.lineHeight;
1116+
}
11141117

11151118
var minHeight = size.scrollerHeight + this.lineHeight;
11161119

src/virtual_renderer_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,56 @@ module.exports = {
134134
});
135135
},
136136

137+
138+
"test scrollbars after value change": function() {
139+
editor.container.style.height = "0px";
140+
editor.setOptions({
141+
maxLines: 8,
142+
});
143+
var renderCount = 0;
144+
editor.renderer.on("afterRender", function(e) {
145+
renderCount++;
146+
});
147+
// horizontal scroll
148+
editor.setValue("\n");
149+
editor.resize(true);
150+
editor.renderer.$loop._flush(); // 1
151+
assert.notOk(editor.renderer.scrollBarH.isVisible);
152+
assert.notOk(editor.renderer.scrollBar.isVisible);
153+
editor.setValue("\n\n\n\n" + "_".repeat(30));
154+
editor.resize(true);
155+
editor.renderer.$loop._flush(); // 2
156+
assert.notOk(editor.renderer.scrollBarH.isVisible);
157+
assert.notOk(editor.renderer.scrollBar.isVisible);
158+
editor.setValue("\n\n\n\n" + "_".repeat(100));
159+
editor.resize(true);
160+
editor.renderer.$loop._flush(); // 3
161+
assert.ok(editor.renderer.scrollBarH.isVisible);
162+
assert.notOk(editor.renderer.scrollBar.isVisible);
163+
// vertical scroll
164+
editor.setValue("\n".repeat(9));
165+
editor.resize(true);
166+
editor.renderer.$loop._flush(); // 4
167+
assert.notOk(editor.renderer.scrollBarH.isVisible);
168+
assert.ok(editor.renderer.scrollBar.isVisible);
169+
// vertical and horizontal scroll
170+
editor.setValue("\n");
171+
editor.resize(true);
172+
editor.renderer.$loop._flush(); // 5
173+
editor.setValue("\n".repeat(9) + "_".repeat(100));
174+
editor.resize(true);
175+
editor.renderer.$loop._flush(); // 6
176+
assert.notOk(editor.renderer.scrollBarH.isVisible);
177+
assert.ok(editor.renderer.scrollBar.isVisible);
178+
editor.resize(true);
179+
editor.renderer.$loop._flush(); // 7
180+
// autosize changes vscroll value in which case updates longestLine
181+
// this is why it renders an extra time
182+
assert.ok(editor.renderer.scrollBarH.isVisible);
183+
assert.ok(editor.renderer.scrollBar.isVisible);
184+
assert.equal(renderCount, 7);
185+
},
186+
137187
"test autosize from 0 height": function() {
138188
editor.container.style.height = "0px";
139189
editor.textInput.getElement().style.position = "fixed";

0 commit comments

Comments
 (0)