mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(desktop): show the text context menu on password fields (#3285)
This commit is contained in:
1 parent
e7859fefb1
commit
510cc1b916
4 files changed
+17
-71
No files matched your search
@@ -140,13 +140,6 @@ let factoryPromise: Promise<HunspellFactory> | null = null;
|
||||
let ipcRegistered = false;
|
||||
let launchModeLogged = false;
|
||||
|
||||
const contextSourceByWebContents = new WeakMap<
|
||||
WebContents,
|
||||
{
|
||||
isTextarea: boolean;
|
||||
ts: number;
|
||||
}
|
||||
>();
|
||||
const norm = (code: string): string => code.toLowerCase();
|
||||
const beginSessionApply = (session: Session): number => {
|
||||
const generation = (sessionApplyGeneration.get(session) ?? 0) + 1;
|
||||
@@ -971,20 +964,6 @@ const suggestWord = (session: Session, word: string): Array<string> => {
|
||||
const ensureSharedIpc = () => {
|
||||
if (ipcRegistered) return;
|
||||
ipcRegistered = true;
|
||||
ipcMain.on(
|
||||
'spellcheck-context-target',
|
||||
(
|
||||
event,
|
||||
payload: {
|
||||
isTextarea?: boolean;
|
||||
},
|
||||
) => {
|
||||
contextSourceByWebContents.set(event.sender, {
|
||||
isTextarea: Boolean(payload?.isTextarea),
|
||||
ts: Date.now(),
|
||||
});
|
||||
},
|
||||
);
|
||||
ipcMain.on(
|
||||
'spellcheck:update-autodetect-text',
|
||||
(
|
||||
@@ -1016,31 +995,6 @@ const ensureSharedIpc = () => {
|
||||
return suggestWord(event.sender.session, word);
|
||||
});
|
||||
};
|
||||
const shouldHandleContextMenu = (webContents: WebContents, params: Electron.ContextMenuParams): boolean => {
|
||||
if (!params['isEditable']) return false;
|
||||
const inputFieldType = (
|
||||
params as {
|
||||
inputFieldType?: string;
|
||||
}
|
||||
).inputFieldType;
|
||||
const isPassword =
|
||||
(
|
||||
params as {
|
||||
isPassword?: boolean;
|
||||
}
|
||||
).isPassword === true ||
|
||||
inputFieldType === 'password' ||
|
||||
(
|
||||
params as {
|
||||
formControlType?: string;
|
||||
}
|
||||
).formControlType === 'password';
|
||||
if (isPassword) return false;
|
||||
const target = contextSourceByWebContents.get(webContents);
|
||||
const targetRecent = target && Date.now() - target.ts < 5000;
|
||||
const isTextLike = inputFieldType === 'plainText' || inputFieldType === 'textarea' || inputFieldType === undefined;
|
||||
return Boolean((targetRecent && target.isTextarea) || isTextLike);
|
||||
};
|
||||
let rendererSpellcheckHandlersRegistered = false;
|
||||
|
||||
export const registerSpellcheck = (webContents: WebContents): void => {
|
||||
@@ -1117,7 +1071,7 @@ export const registerSpellcheck = (webContents: WebContents): void => {
|
||||
});
|
||||
}
|
||||
webContents.on('context-menu', (event, params) => {
|
||||
if (!shouldHandleContextMenu(webContents, params)) return;
|
||||
if (!params.isEditable) return;
|
||||
event.preventDefault();
|
||||
const cur = sessionState.get(session) ?? {...defaultState};
|
||||
const resolved = sessionResolvedEngine.get(session) ?? resolveEngine(cur, session);
|
||||
|
||||
Reference in new issue
Block a user