Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32b9199

Browse files
authored
Merge pull request atom#1281 from atom/ku-fix-scroll-bugs
Scroll to selected diff line only if head of selection changes
2 parents 2774bb9 + 2f04381 commit 32b9199

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/views/hunk-view.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,17 @@ export default class HunkView extends React.Component {
9494
this.lineElements.set(line, element);
9595
}
9696

97-
componentDidUpdate() {
98-
const selectedLine = Array.from(this.props.selectedLines)[0];
99-
if (selectedLine && this.lineElements.get(selectedLine)) {
100-
// QUESTION: why is this setTimeout needed?
101-
const element = this.lineElements.get(selectedLine);
102-
setTimeout(() => {
103-
element.scrollIntoViewIfNeeded();
104-
}, 0);
105-
} else if (this.props.headHunk === this.props.hunk) {
106-
this.element.scrollIntoViewIfNeeded();
107-
} else if (this.props.headLine && this.lineElements.has(this.props.headLine)) {
108-
this.lineElements.get(this.props.headLine).scrollIntoViewIfNeeded();
97+
componentDidUpdate(prevProps) {
98+
if (prevProps.headLine !== this.props.headLine) {
99+
if (this.props.headLine && this.lineElements.has(this.props.headLine)) {
100+
this.lineElements.get(this.props.headLine).scrollIntoViewIfNeeded();
101+
}
102+
}
103+
104+
if (prevProps.headHunk !== this.props.headHunk) {
105+
if (this.props.headHunk === this.props.hunk) {
106+
this.element.scrollIntoViewIfNeeded();
107+
}
109108
}
110109
}
111110
}

0 commit comments

Comments
 (0)