Skip to content

Commit

Permalink
feat(electron): spellcheck setting
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Nov 7, 2024
1 parent 727130e commit 5759026
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { join } from 'node:path';

import {
app,
Menu,
MenuItem,
session,
type View,
type WebContents,
Expand Down Expand Up @@ -816,13 +818,42 @@ export class WebContentViewsManager {
transparent: true,
contextIsolation: true,
sandbox: false,
spellcheck: false, // TODO(@pengx17): enable?
spellcheck: true, // TODO(@pengx17): enable?
preload: join(__dirname, './preload.js'), // this points to the bundled preload module
// serialize exposed meta that to be used in preload
additionalArguments: additionalArguments,
},
});

view.webContents.on('context-menu', (event, params) => {
const menu = new Menu();

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

// Allow users to add the misspelled word to the dictionary
if (params.misspelledWord) {
menu.append(
new MenuItem({
label: 'Add to dictionary',
click: () =>
view.webContents.session.addWordToSpellCheckerDictionary(
params.misspelledWord
),
})
);
}

menu.popup();
});

this.webViewsMap$.next(this.tabViewsMap.set(viewId, view));
let unsub = () => {};

Expand Down

0 comments on commit 5759026

Please sign in to comment.