1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-14 15:35:35 +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 => { this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick); link.addEventListener('click', this.onLinkClick);
}); });
this.getTitlesInfo();
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@ -57,6 +59,9 @@ class WikiMarkdownViewer extends React.Component {
this.links.forEach(link => { this.links.forEach(link => {
link.addEventListener('click', this.onLinkClick); link.addEventListener('click', this.onLinkClick);
}); });
if (this.titlesInfo.length === 0) {
this.getTitlesInfo();
}
} }
componentWillUnmount() { componentWillUnmount() {
@ -66,8 +71,13 @@ class WikiMarkdownViewer extends React.Component {
}); });
} }
onContentRendered = (markdownViewer) => { getTitlesInfo = () => {
this.titlesInfo = markdownViewer.titlesInfo; 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) => { onLinkClick = (event) => {
@ -170,7 +180,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'} scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent} markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex} activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
modifyValueBeforeRender={this.modifyValueBeforeRender} modifyValueBeforeRender={this.modifyValueBeforeRender}
/> />
); );
@ -182,7 +191,6 @@ class WikiMarkdownViewer extends React.Component {
scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'} scriptSource={mediaUrl + 'js/mathjax/tex-svg.js'}
markdownContent={this.props.markdownContent} markdownContent={this.props.markdownContent}
activeTitleIndex={this.state.activeTitleIndex} activeTitleIndex={this.state.activeTitleIndex}
onContentRendered={this.onContentRendered}
/> />
); );
} }