Skip to content

Commit

Permalink
fix: Fixed scrolling code lenses into view
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester committed May 29, 2022
1 parent bf2c7e2 commit 108d059
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/ace/ext/code_lens.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function renderWidgets(changes, renderer) {
if (indent == -1)
indent = 0;
left += indent * config.characterWidth;
left -= renderer.scrollLeft;
lensContainer.style.paddingLeft = padding + left + "px";
}
while (index < lensElements.length)
Expand Down Expand Up @@ -146,6 +145,7 @@ exports.setLenses = function(session, lenses) {
firstRow = row;
});
session._emit("changeFold", {data: {start: {row: firstRow}}});
return firstRow;
};

function attachToEditor(editor) {
Expand All @@ -154,8 +154,9 @@ function attachToEditor(editor) {
if (!editor.$codeLensClickHandler) {
editor.$codeLensClickHandler = function(e) {
var command = e.target.lensCommand;
if (command)
editor.execCommand(command.id, command.arguments);
if (!command) return;
editor.execCommand(command.id, command.arguments);
editor._emit("codeLensClick", e);
};
event.addListener(editor.container, "click", editor.$codeLensClickHandler, editor);
}
Expand Down Expand Up @@ -186,14 +187,19 @@ function attachToEditor(editor) {
function applyLenses() {
var cursor = session.selection.cursor;
var oldRow = session.documentToScreenRow(cursor);
exports.setLenses(session, lenses);
var scrollTop = session.getScrollTop();
var firstRow = exports.setLenses(session, lenses);

var lastDelta = session.$undoManager && session.$undoManager.$lastDelta;
if (lastDelta && lastDelta.action == "remove" && lastDelta.lines.length > 1)
return;
var row = session.documentToScreenRow(cursor);
var lineHeight = editor.renderer.layerConfig.lineHeight;
var top = session.getScrollTop() + (row - oldRow) * lineHeight;
// special case for the lens on line 0, because it can't be scrolled into view with keyboard
if (firstRow == 0 && scrollTop < lineHeight /4 && scrollTop > -lineHeight/4) {
top = -lineHeight;
}
session.setScrollTop(top);
}
};
Expand Down

0 comments on commit 108d059

Please sign in to comment.