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

改进 getSearch 函数实现 #7089

Merged
merged 4 commits into from
Jan 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/layout/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ export const JSONToLayout = (isStart: boolean) => {
}
// https://github.com/siyuan-note/siyuan/pull/7086
const openId = getSearch("id", window.location.href);
if (openId) {
if (openId !== null) {
openFileById({
id: getSearch("id", window.location.href),
id: openId,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: getSearch("focus", window.location.href) === "1"
});
Expand Down
4 changes: 2 additions & 2 deletions app/src/mobile/util/initFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export const initFramework = () => {
initEditorName();
if (getOpenNotebookCount() > 0) {
const openId = getSearch("id", window.location.href);
if (openId) {
openMobileFileById(getSearch("id", window.location.href),
if (openId !== null) {
openMobileFileById(openId,
getSearch("focus", window.location.href) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
} else {
const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ export class WYSIWYG {
openBy(linkAddress, "app");
} else {
const page = getSearch("page", linkAddress);
openAsset(linkPathname, page === "" ? undefined : parseInt(page), "right");
openAsset(linkPathname, page === null ? undefined : parseInt(page), "right");
}
} else {
/// #if !BROWSER
Expand Down
18 changes: 4 additions & 14 deletions app/src/util/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ export const getRandom = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
};

export const getSearch = (key: string, link = window.location.search) => {
if (link.indexOf("?") === -1) {
return "";
}
let value = "";
const data = link.split("?")[1].split("&");
data.find(item => {
const keyValue = item.split("=");
if (keyValue[0] === key) {
value = keyValue[1];
return true;
}
});
return value;
export const getSearch: (key: string, link?: string) => string | null = (key: string, link = window.location.search) => {
// REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
const urlSearchParams = new URLSearchParams(link);
return urlSearchParams.get(key);
};

export const isBrowser = () => {
Expand Down