Skip to content

Commit

Permalink
Fix scroll navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Mar 18, 2019
1 parent f11002e commit 8ca216e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/git-providers/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,11 @@ export function getChanges(lines) {
i++;
}

if (currentChange) {
currentChange.end = i - 1;
changes.push(currentChange);
currentChange = null;
}

return changes;
}
10 changes: 9 additions & 1 deletion src/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import useChildren from "./use-virtual-children";
import "./scroller.css";
import useSpring from "./use-spring";
import { nextIndex, prevIndex, closestIndex, getScrollTop } from "./utils";
import { nextIndex, prevIndex, getScrollTop } from "./utils";

const initialState = {
snap: false,
Expand All @@ -23,6 +23,8 @@ export default function Scroller({

const reducer = (prevState, action) => {
switch (action.type) {
case "unsnap":
return !prevState.snap ? prevState : { ...prevState, snap: false };
case "change-area":
if (snapAreas.length === 0) {
return prevState;
Expand Down Expand Up @@ -129,6 +131,12 @@ export default function Scroller({
// });
// }, [snapAreas]);

React.useEffect(() => {
dispatch({
type: "unsnap"
});
}, [snapAreas]);

React.useLayoutEffect(() => {
if (snap) {
ref.current.scrollTop = top;
Expand Down

0 comments on commit 8ca216e

Please sign in to comment.