Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.
/ liandi Public archive

Commit

Permalink
🎨 search
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 16, 2020
1 parent a6e4540 commit 09794fe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
22 changes: 20 additions & 2 deletions app/src/config/search.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {destroyDialog} from "../util/dialog";
import {i18n} from "../i18n";

export const initConfigSearch = (liandi: ILiandi, element: HTMLElement) => {
const configIndex = [
['markdown'],
['markdown', i18n.zh_CN.config, i18n.en_US.config, i18n.en_US.autoSpace, i18n.zh_CN.autoSpace,
i18n.en_US.fixTermTypo, i18n.zh_CN.fixTermTypo, i18n.en_US.chinesePunctuation,
i18n.zh_CN.chinesePunctuation, i18n.en_US.inlineMathDigit, i18n.zh_CN.inlineMathDigit,
i18n.en_US.mathEngine, i18n.zh_CN.mathEngine, 'katex', 'mathjax'],
['white', 'dark', 'theme', '主题'],
['zh_CN', 'en_US', 'language', '语言']
['zh_CN', 'en_US', 'language', '语言'],
['About', '关于', i18n.zh_CN.checkUpdate, i18n.en_US.checkUpdate]
];
const inputElement = element.querySelector('.input') as HTMLInputElement;
const updateTab = () => {
Expand Down Expand Up @@ -35,6 +42,8 @@ export const initConfigSearch = (liandi: ILiandi, element: HTMLElement) => {
} else {
tabPanelElement.style.display = 'none';
}

inputElement.focus()
};

inputElement.addEventListener('compositionend', () => {
Expand All @@ -46,4 +55,13 @@ export const initConfigSearch = (liandi: ILiandi, element: HTMLElement) => {
}
updateTab();
});
inputElement.addEventListener('keydown', (event) => {
if (event.isComposing) {
return;
}
if (event.key === 'Escape') {
destroyDialog()
event.preventDefault();
}
})
};
16 changes: 11 additions & 5 deletions app/src/menu/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {remote, shell} from 'electron';
import {i18n} from '../i18n';
import * as path from 'path';
import {showMessage} from '../util/message';
import {destroyDialog, dialog} from '../util/dialog';
import {bindDialogInput, destroyDialog, dialog} from '../util/dialog';
import {validateName} from '../util/rename';
import {getPath, removeLastPath} from '../util/path';

Expand Down Expand Up @@ -45,12 +45,12 @@ export const newFile = (liandi: ILiandi) => {
});

const dialogElement = document.querySelector('#dialog');
(dialogElement.querySelector('.input') as HTMLElement).focus();
const inputElement = dialogElement.querySelector('.input') as HTMLInputElement;
dialogElement.querySelector('.button--cancel').addEventListener('click', () => {
destroyDialog();
});
dialogElement.querySelector('.button').addEventListener('click', () => {
const name = (dialogElement.querySelector('.input') as HTMLInputElement).value;
const name = inputElement.value;
if (!validateName(liandi, name)) {
return false;
}
Expand All @@ -66,6 +66,9 @@ export const newFile = (liandi: ILiandi) => {
});
destroyDialog();
});
bindDialogInput(inputElement, () => {
(dialogElement.querySelector('.button') as HTMLButtonElement).click();
})
}
});
};
Expand All @@ -87,12 +90,12 @@ export const newFolder = (liandi: ILiandi) => {
});

const dialogElement = document.querySelector('#dialog');
(dialogElement.querySelector('.input') as HTMLElement).focus();
const inputElement = dialogElement.querySelector('.input') as HTMLInputElement;
dialogElement.querySelector('.button--cancel').addEventListener('click', () => {
destroyDialog();
});
dialogElement.querySelector('.button').addEventListener('click', () => {
const name = (dialogElement.querySelector('.input') as HTMLInputElement).value;
const name = inputElement.value;
if (!validateName(liandi, name)) {
return false;
}
Expand All @@ -107,6 +110,9 @@ export const newFolder = (liandi: ILiandi) => {
});
destroyDialog();
});
bindDialogInput(inputElement, () => {
(dialogElement.querySelector('.button') as HTMLButtonElement).click();
})
}
});
};
17 changes: 10 additions & 7 deletions app/src/menu/files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {remote} from 'electron';
import {i18n} from '../i18n';
import {Constants} from '../constants';
import {destroyDialog, dialog} from '../util/dialog';
import {bindDialogInput, destroyDialog, dialog} from '../util/dialog';
import {rename} from '../util/rename';
import {newFile, newFolder, showInFolder} from './commonMenuItem';

Expand Down Expand Up @@ -31,10 +31,10 @@ export const initFilesMenu = (liandi: ILiandi) => {
destroyDialog();
});
dialogElement.querySelector('.button').addEventListener('click', () => {
liandi.ws.send('remove',{
url: itemData.url,
path: itemData.path
});
liandi.ws.send('remove', {
url: itemData.url,
path: itemData.path
});
if (liandi.current.dir.url === itemData.url && itemData.path === liandi.current.path) {
liandi.editors.sendMessage(Constants.LIANDI_EDITOR_CLOSE);
liandi.current.path = '';
Expand All @@ -58,18 +58,21 @@ export const initFilesMenu = (liandi: ILiandi) => {
width: 400
});
const dialogElement = document.querySelector('#dialog');
(dialogElement.querySelector('.input') as HTMLElement).focus();
const inputElement = dialogElement.querySelector('.input') as HTMLInputElement
dialogElement.querySelector('.button--cancel').addEventListener('click', () => {
destroyDialog();
});
dialogElement.querySelector('.button').addEventListener('click', () => {
const newPath = rename(liandi, (dialogElement.querySelector('.input') as HTMLInputElement).value,
const newPath = rename(liandi, inputElement.value,
itemData.url, itemData.path);

if (newPath) {
destroyDialog();
}
});
bindDialogInput(inputElement, () => {
(dialogElement.querySelector('.button') as HTMLButtonElement).click();
})
}
}));

Expand Down
7 changes: 7 additions & 0 deletions app/src/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export const initSearch = (liandi: ILiandi) => {
});
});
inputElement.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.isComposing) {
return;
}
if (event.key === 'Escape') {
destroyDialog()
event.preventDefault();
}
let currentList: HTMLElement = dialogElement.querySelector('div[data-name="search"] .list__item--current');

if (event.code === 'ArrowDown') {
Expand Down
17 changes: 17 additions & 0 deletions app/src/util/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ export const dialog = (options: {
dialogMainElement.style.width = `${options.width}px`;
dialogElement.style.display = 'block';
};

export const bindDialogInput = (inputElement: HTMLInputElement, enterEvent?: () => void) => {
inputElement.focus();
inputElement.addEventListener('keydown', (event) => {
if (event.isComposing) {
return;
}
if (event.key === 'Escape') {
destroyDialog()
event.preventDefault();
}
if (event.key === 'Enter' && enterEvent) {
enterEvent()
event.preventDefault();
}
})
}

0 comments on commit 09794fe

Please sign in to comment.