Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(files): Add smooth animation via clicking on heading
Signed-off-by: julia.kirschenheuter <[email protected]>
  • Loading branch information
JuliaKirschenheuter authored and mejo- committed Jun 23, 2025
commit 812e44ed2257d62772eba986ea318cfc3c131fd3
12 changes: 8 additions & 4 deletions src/components/Editor/TableOfContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[`editor--toc__item--${heading.level}`]: true,
[`editor--toc__item--previous-${heading.previous}`]: heading.previous > 0,
}">
<a :href="`#${heading.id}`" @click.prevent="goto(heading)">
<a :href="`#${heading.id}`" class="editor--toc__item-link" @click.prevent="goto(heading)">
{{ heading.text }}
</a>
</li>
Expand Down Expand Up @@ -45,10 +45,10 @@
},
methods: {
goto(heading) {
document.getElementById(heading.id).scrollIntoView()

const element = this.$root.$el.querySelector(`#${heading.id}`)
element.scrollIntoView({ block: 'start', behavior: 'smooth' })

Check warning on line 49 in src/components/Editor/TableOfContents.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/TableOfContents.vue#L48-L49

Added lines #L48 - L49 were not covered by tests
this.$nextTick(() => {
window.location.hash = heading.id
window.history.replaceState(window.history.state, '', `#${heading.id}`)

Check warning on line 51 in src/components/Editor/TableOfContents.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/TableOfContents.vue#L51

Added line #L51 was not covered by tests
})
},
},
Expand Down Expand Up @@ -96,6 +96,10 @@
color: var(--color-primary-element-hover);
}

&-link {
scroll-margin-top: calc(var(--default-clickable-area) + 4 * var(--default-grid-baseline));
}

&--1 {
--padding-left: 0rem;
font-weight: 600;
Expand Down
3 changes: 3 additions & 0 deletions src/css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ div.ProseMirror {
transition-duration: .15s;
transition-property: opacity;
transition-timing-function: cubic-bezier(.4,0,.2,1);
scroll-margin-top: calc(
var(--default-clickable-area) + 4 * var(--default-grid-baseline)
);
}

&:hover .heading-anchor {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/headingAnchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
*/
function handleClick(event) {
event.stopPropagation()
event.target.scrollIntoView()
window.location.hash = event.target.getAttribute('href')
event.preventDefault()
event.target.scrollIntoView({ block: 'start', behavior: 'smooth' })
window.history.replaceState({}, '', event.target.getAttribute('href'))

Check warning on line 150 in src/plugins/headingAnchor.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/headingAnchor.js#L148-L150

Added lines #L148 - L150 were not covered by tests
}
Loading