debugger
debugger copied to clipboard
[Stepping] aligns line every time
When we refactored scrolling last month, we removed a check that used to ensure that we'd only scroll if the line were not visible. We should bring that back because now it's very jump :runner:
STR:
- go to todomvc
- add a breakpoint in todoview.js#33
- add a todo in the app
- start stepping
notice how it always scrolls!

GIST
diff --git a/src/utils/editor/index.js b/src/utils/editor/index.js
index 661b01b..9e2d5d8 100644
--- a/src/utils/editor/index.js
+++ b/src/utils/editor/index.js
@@ -91,7 +91,26 @@ export function scrollToColumn(codeMirror: any, line: number, column: number) {
const centeredX = Math.max(left - scroller.offsetWidth / 2, 0);
const centeredY = Math.max(top - scroller.offsetHeight / 2, 0);
- codeMirror.scrollTo(centeredX, centeredY);
+ if (!isVisible(codeMirror, line, column)) {
+ // we probably also want to check to see if the column is visible
+ codeMirror.scrollTo(centeredX, centeredY);
+ }
+}
+
+// this approach comes from alignLine
+// we could also check the top / left we have above or some other strategy...
+function isVisible(codeMirror, line, column) {
+ const editorClientRect = codeMirror.getWrapperElement().getBoundingClientRect();
+
+ const from = codeMirror.lineAtHeight(editorClientRect.top, "page");
+ const to = codeMirror.lineAtHeight(
+ editorClientRect.height + editorClientRect.top,
+ "page"
+ );
+
+ const isLineVisible = line >= to && line <= from;
+ const isColumnVisible = false;
+ return isLineVisible && isColumnVisible;
}
export function toSourceLocation(
/claim
Thanks for claiming the issue! :wave:
Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.
:fox_face: Debugger team!