Skip to content

Commit

Permalink
fix: display collapsed items sections as selected
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Aug 20, 2021
1 parent 652e3ac commit f276863
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
function scrollToLastItem() {
setTimeout(() => {
const lastItem = refNavigationBar && refNavigationBar.querySelector('div:last-child')
// console.log('lastItem', lastItem)
if (lastItem && lastItem.scrollIntoView) {
debug('scroll to lastItem', path)
// debug('scroll to lastItem', path)
lastItem.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
}
})
Expand Down
8 changes: 8 additions & 0 deletions src/lib/components/modes/treemode/CollapsedItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<script>
import { INDENTATION_WIDTH } from '../../../constants.js'
import { getExpandItemsSections } from '../../../logic/expandItemsSections.js'
import { compileJSONPointer } from 'immutable-json-patch'
export let visibleSections
export let sectionIndex
export let total
export let path
export let selection
/** @type {function (path: Path, section: Section)} */
export let onExpandSection
Expand All @@ -17,6 +19,11 @@
$: startIndex = visibleSection.end
$: endIndex = visibleSections[sectionIndex + 1] ? visibleSections[sectionIndex + 1].start : total
$: selected =
selection && selection.pathsMap
? selection.pathsMap[compileJSONPointer(path.concat(startIndex))] === true
: false
$: expandItemsSections = getExpandItemsSections(startIndex, endIndex)
// TODO: this is duplicated from the same function in JSONNode
Expand All @@ -33,6 +40,7 @@

<div
class="collapsed-items"
class:selected
on:mousemove={handleMouseMove}
style={getIndentationStyle(path.length + 2)}
>
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/modes/treemode/JSONNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
total={value.length}
{path}
{onExpandSection}
{selection}
/>
{/if}
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
background-color: $selection-background;
}

:global(.collapsed-items.selected),
&.selected :global(.collapsed-items),
&.selected-value :global(.collapsed-items) {
// TODO: this css is copied from CollapsedItems.scss. Figure out how to reuse this smartly with CSS or SASS
Expand Down

0 comments on commit f276863

Please sign in to comment.