1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-14 07:24:58 +00:00

Merge pull request #5190 from haiwen/repair-wiki-markdown-viewer

repair refresh page scroll bug
This commit is contained in:
Daniel Pan 2022-05-27 15:54:54 +08:00 committed by GitHub
commit 05064ff72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,8 @@ class WikiMarkdownViewer extends React.Component {
this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick);
});
this.getTitlesInfo();
}
componentWillReceiveProps(nextProps) {
@ -57,6 +59,9 @@ class WikiMarkdownViewer extends React.Component {
this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick);
});
if (this.titlesInfo.length === 0) {
this.getTitlesInfo();
}
}
componentWillUnmount() {
@ -66,8 +71,13 @@ class WikiMarkdownViewer extends React.Component {
});
}
onContentRendered = (markdownViewer) => {
this.titlesInfo = markdownViewer.titlesInfo;
getTitlesInfo = () => {
let titlesInfo = [];
let headingList = document.querySelectorAll('h2[id^="user-content"], h3[id^="user-content"]');
for (let i = 0; i < headingList.length; i++) {
titlesInfo.push(headingList[i].offsetTop);
}
this.titlesInfo = titlesInfo;
}
onLinkClick = (event) => {
@ -170,7 +180,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
modifyValueBeforeRender={this.modifyValueBeforeRender}
/>
);
@ -182,7 +191,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
/>
);
}