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

Add built-in support for spellchecking #94

Merged
merged 16 commits into from
Apr 14, 2020
Merged
7 changes: 6 additions & 1 deletion fixture-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ contextMenu({
(async () => {
await app.whenReady();

await (new BrowserWindow()).loadFile(path.join(__dirname, 'fixture.html'));
await (new BrowserWindow({
webPreferences: {
nodeIntegration: true,
spellcheck: true
}
})).loadFile(path.join(__dirname, 'fixture.html'));
})();
5 changes: 3 additions & 2 deletions fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contextMenu({
type: 'separator'
}
],
append: () => {},
append: () => { },
showCopyImageAddress: true,
showSaveImageAs: true,
showInspectElement: false
Expand All @@ -45,7 +45,8 @@ contextMenu({

await (new BrowserWindow({
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
spellcheck: true
}
})).loadFile(path.join(__dirname, 'fixture.html'));
})();
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ declare namespace contextMenu {
- `showSaveImageAs`
- `showInspectElement`
- `showServices`

- `dictionary`

@default [defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.copyLink(), defaultActions.copyImage(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.separator(), defaultActions.inspect()]
*/
readonly menu?: (
Expand Down
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,24 @@ const create = (win, options) => {

const shouldShowInspectElement = typeof options.showInspectElement === 'boolean' ? options.showInspectElement : isDev;

const dictSuggestions = [];
for (let index = 0; index < props.dictionarySuggestions.length; index++) {
dictSuggestions.push(
{
id: 'dictSuggestions',
label: props.dictionarySuggestions[index],
visible: props.isEditable && hasText && props.misspelledWord,
click(menuItem) {
const target = webContents(win);
target.insertText(menuItem.label);
}
}
);
}

let menuTemplate = [
defaultActions.separator(),
...dictSuggestions,
defaultActions.separator(),
options.showLookUpSelection !== false && defaultActions.lookUpSelection(),
defaultActions.separator(),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@types/node": "^12.0.10",
"ava": "^2.1.0",
"electron": "^7.1.1",
"electron": "^8.0.0",
"tsd": "^0.10.0",
"xo": "^0.25.3"
},
Expand All @@ -47,4 +47,4 @@
"browser"
]
}
}
}
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ The following options are ignored when `menu` is used:
- `showSaveImageAs`
- `showInspectElement`
- `showServices`

- `dictionary`

Default actions:

- `separator`
Expand All @@ -200,6 +201,7 @@ Default actions:
- `copyLink`
- `inspect`
- `services`
- `dictionary`

Example:

Expand Down