-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Pass down ref * Clean up dangling widgets, calculate line position better
- Loading branch information
Showing
7 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
app/javascript/components/bootcamp/SolveExercisePage/CodeMirror/scrollToLine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { EditorView } from '@codemirror/view' | ||
|
||
export function scrollToLine(view: EditorView, line: number): void { | ||
export function scrollToLine(view: EditorView | null, line: number): void { | ||
if (!view) return | ||
const doc = view.state.doc | ||
const linePos = doc.line(line) | ||
if (linePos) { | ||
view.dispatch({ | ||
effects: EditorView.scrollIntoView(linePos.from, { y: 'center' }), | ||
}) | ||
const lineBlock = view.lineBlockAt(linePos.from) | ||
if (lineBlock) { | ||
const viewportHeight = view.scrollDOM.clientHeight | ||
const blockHeight = lineBlock.bottom - lineBlock.top | ||
|
||
const centeredTop = lineBlock.top - viewportHeight / 2 + blockHeight / 2 | ||
|
||
view.scrollDOM.scrollTo({ top: centeredTop }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters