Skip to content

Commit

Permalink
feat(electron): enable spell checking
Browse files Browse the repository at this point in the history
  • Loading branch information
wardellbagby committed Apr 9, 2022
1 parent dd82ce4 commit deaaaa9
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion apps/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isDevelopment, isUnderTest } from '@lyricistant/common/BuildModes';
import { RendererDelegate } from '@lyricistant/common/Delegates';
import { Logger } from '@lyricistant/common/Logger';
import { DIContainer } from '@wessberg/di';
import { app, BrowserWindow, dialog, Menu, shell } from 'electron';
import { app, BrowserWindow, dialog, Menu, MenuItem, shell } from 'electron';
import debug from 'electron-debug';

export let mainWindow: BrowserWindow;
Expand Down Expand Up @@ -142,6 +142,34 @@ const onAppComponentCreated = () => {
}
};

const setupSpellcheck = (window: BrowserWindow) => {
window.webContents.on('context-menu', (event, params) => {
const menu = new Menu();

for (const suggestion of params.dictionarySuggestions) {
menu.append(
new MenuItem({
label: suggestion,
click: () => window.webContents.replaceMisspelling(suggestion),
})
);
}

if (params.misspelledWord) {
menu.append(new MenuItem({ type: 'separator' }));
menu.append(
new MenuItem({
label: 'Add to dictionary',
click: () =>
window.webContents.session.addWordToSpellCheckerDictionary(
params.misspelledWord
),
})
);
}
menu.popup();
});
};
const createWindow = (): void => {
mainWindow = new BrowserWindow({
width: 1000,
Expand Down Expand Up @@ -217,6 +245,8 @@ const createWindow = (): void => {
shell.openExternal(details.url);
return { action: 'deny' };
});

setupSpellcheck(mainWindow);
setMenu();
};

Expand Down

0 comments on commit deaaaa9

Please sign in to comment.