Skip to content

Commit

Permalink
Merge pull request #124 from aramperes/patch-118
Browse files Browse the repository at this point in the history
#118 Fix tree desync by taking :target into consideration
  • Loading branch information
berzniz authored Sep 19, 2020
2 parents d4b2a0e + aefa386 commit 80f5f69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/components/tree/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import Actions from '../actions'
import { createFileTree, isElementVisible, StorageSync, getBrowserApi } from '../../lib'
import { createFileTree, isElementVisible, StorageSync, getBrowserApi, isElementTargetAndVisible } from '../../lib'
import { createTree } from '../../createTree'
import BodyColor from '../bodyColor'

Expand Down Expand Up @@ -118,7 +118,7 @@ class Tree extends React.Component {
const { visibleElement } = this.state
const { root } = this.props
const { diffElements = [] } = root
const nextVisibleElement = diffElements.find(isElementVisible)
const nextVisibleElement = diffElements.find(isElementTargetAndVisible) || diffElements.find(isElementVisible)
if (nextVisibleElement !== visibleElement) {
this.setState({
visibleElement: nextVisibleElement
Expand Down
10 changes: 10 additions & 0 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export const isElementVisible = (el) => {
return (vertInView && horInView)
}

export const isElementTarget = (el) => {
if (!el) {
return false
}

return el.matches(':target')
}

export const isElementTargetAndVisible = (el) => isElementTarget(el) && isElementVisible(el)

const EMPTY_FILTER = ''

export const getBrowserApi = () => {
Expand Down

0 comments on commit 80f5f69

Please sign in to comment.