Implement simple spellchecker

This commit is contained in:
Yuya Ochiai
2017-04-20 21:32:34 +09:00
parent 4d884a217a
commit 84d0ec432a
15 changed files with 312 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
const {ipcRenderer} = require('electron');
const electronContextMenu = require('electron-context-menu');
function getSuggestionsMenus(win, suggestions) {
return suggestions.map((s) => ({
label: s,
click() {
(win.webContents || win.getWebContents()).replaceMisspelling(s);
}
}));
}
module.exports = {
setup(win) {
electronContextMenu({
window: win,
prepend(params) {
if (params.isEditable && params.misspelledWord !== '') {
const suggestions = ipcRenderer.sendSync('get-spelling-suggestions', params.misspelledWord);
return getSuggestionsMenus(win, suggestions);
}
return [];
}
});
}
};