Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wiki title bug #7254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion frontend/src/pages/wiki2/index.js
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ class Wiki extends Component {
let errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
}, 1000);
}, 500);

saveWikiConfig = (wikiConfig, isUpdateBySide = false) => {
this.setState({
36 changes: 24 additions & 12 deletions frontend/src/pages/wiki2/utils/index.js
Original file line number Diff line number Diff line change
@@ -53,20 +53,32 @@ const getWikPageLink = (pageId) => {
return `${origin}${pathname}?page_id=${pageId}`;
};

const throttle = (fn, delay) => {
let timer;
return function () {
let _this = this;
let args = arguments;
if (timer) {
return;
function throttle(func, delay) {
let lastCall = 0;
let timeoutId = null;
let lastArgs = null;

return function (...args) {
const now = new Date().getTime();
lastArgs = args;

if (now - lastCall >= delay) {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}
lastCall = now;
func(...args);
} else if (!timeoutId) {
timeoutId = setTimeout(() => {
lastCall = new Date().getTime();
timeoutId = null;
func(...lastArgs);
}, delay - (now - lastCall));
}
timer = setTimeout(function () {
fn.apply(_this, args);
timer = null;
}, delay);
};
};
}


// Find the path array from the root to the leaf based on the currentPageId (leaf)
const getPaths = (navigation, currentPageId, pages, isGetPathStr) => {
Original file line number Diff line number Diff line change
@@ -30,11 +30,15 @@ function PageTitleEditor({ isUpdateBySide, currentPageConfig, onUpdatePage }) {
range.setStart(startContainer, startOffset);
range.setEnd(endContainer, endOffset);

range.selectNodeContents(contentEditableRef.current);
range.collapse(false);

const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
contentEditableRef.current.focus();
}
}, [pageName.length]);
}, [pageName]);

const onKeyDown = (event) => {
if (event.keyCode === 13) {