From 7430843c9b5c7a9bd48cff202ffa45adf4a12df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Thu, 5 Sep 2024 22:13:10 +0700 Subject: [PATCH] Improve go-to-definition scroll to position the cursor near the viewport top --- assets/js/hooks/cell.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/js/hooks/cell.js b/assets/js/hooks/cell.js index 9c9a62740..967a69b0f 100644 --- a/assets/js/hooks/cell.js +++ b/assets/js/hooks/cell.js @@ -365,11 +365,16 @@ const Cell = { scrollEditorCursorIntoViewIfNeeded() { const element = this.currentEditor().getElementAtCursor(); + // Scroll to the cursor, positioning it near the top of the viewport + element.style.scrollMarginTop = "128px"; + scrollIntoView(element, { scrollMode: "if-needed", behavior: "instant", - block: "center", + block: "start", }); + + element.style.scrollMarginTop = undefined; }, };