mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
fix: pull-based clipboard text and cursor at end with br
This commit is contained in:
parent
4a5a28805d
commit
f3d6ae95e1
5 changed files with 16 additions and 21 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { BrowserWindow, clipboard, globalShortcut, screen } from 'electron';
|
||||
import { BrowserWindow, clipboard, globalShortcut, ipcMain, screen } from 'electron';
|
||||
import path from 'path';
|
||||
import { IPC_CHANNELS } from '../ipc/channels';
|
||||
import { getServerPort } from './server';
|
||||
|
||||
const SHORTCUT = 'CommandOrControl+Option+S';
|
||||
let quickAskWindow: BrowserWindow | null = null;
|
||||
let pendingText = '';
|
||||
|
||||
function hideQuickAsk(): void {
|
||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||
|
|
@ -62,22 +63,20 @@ export function registerQuickAsk(): void {
|
|||
const text = clipboard.readText().trim();
|
||||
if (!text) return;
|
||||
|
||||
const isExisting = quickAskWindow && !quickAskWindow.isDestroyed();
|
||||
pendingText = text;
|
||||
const cursor = screen.getCursorScreenPoint();
|
||||
const win = createQuickAskWindow(cursor.x, cursor.y);
|
||||
|
||||
if (isExisting) {
|
||||
win.webContents.send(IPC_CHANNELS.QUICK_ASK_TEXT, text);
|
||||
} else {
|
||||
win.webContents.once('did-finish-load', () => {
|
||||
win.webContents.send(IPC_CHANNELS.QUICK_ASK_TEXT, text);
|
||||
});
|
||||
}
|
||||
createQuickAskWindow(cursor.x, cursor.y);
|
||||
});
|
||||
|
||||
if (!ok) {
|
||||
console.log(`Quick-ask: failed to register ${SHORTCUT}`);
|
||||
}
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.QUICK_ASK_TEXT, () => {
|
||||
const text = pendingText;
|
||||
pendingText = '';
|
||||
return text;
|
||||
});
|
||||
}
|
||||
|
||||
export function unregisterQuickAsk(): void {
|
||||
|
|
|
|||
|
|
@ -17,11 +17,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
ipcRenderer.removeListener(IPC_CHANNELS.DEEP_LINK, listener);
|
||||
};
|
||||
},
|
||||
onQuickAskText: (callback: (text: string) => void) => {
|
||||
const listener = (_event: unknown, text: string) => callback(text);
|
||||
ipcRenderer.on(IPC_CHANNELS.QUICK_ASK_TEXT, listener);
|
||||
return () => {
|
||||
ipcRenderer.removeListener(IPC_CHANNELS.QUICK_ASK_TEXT, listener);
|
||||
};
|
||||
},
|
||||
getQuickAskText: () => ipcRenderer.invoke(IPC_CHANNELS.QUICK_ASK_TEXT),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -119,7 +119,9 @@ export const InlineMentionEditor = forwardRef<InlineMentionEditorRef, InlineMent
|
|||
|
||||
useEffect(() => {
|
||||
if (!initialText || !editorRef.current) return;
|
||||
editorRef.current.textContent = initialText + "\n";
|
||||
editorRef.current.innerText = initialText;
|
||||
editorRef.current.appendChild(document.createElement("br"));
|
||||
editorRef.current.appendChild(document.createElement("br"));
|
||||
setIsEmpty(false);
|
||||
onChange?.(initialText, Array.from(mentionedDocs.values()));
|
||||
editorRef.current.focus();
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ const Composer: FC = () => {
|
|||
|
||||
const [quickAskText, setQuickAskText] = useState<string | undefined>();
|
||||
useEffect(() => {
|
||||
return window.electronAPI?.onQuickAskText((text) => {
|
||||
window.electronAPI?.getQuickAskText().then((text) => {
|
||||
if (text) setQuickAskText(text);
|
||||
});
|
||||
}, []);
|
||||
|
|
|
|||
2
surfsense_web/types/window.d.ts
vendored
2
surfsense_web/types/window.d.ts
vendored
|
|
@ -10,7 +10,7 @@ interface ElectronAPI {
|
|||
openExternal: (url: string) => void;
|
||||
getAppVersion: () => Promise<string>;
|
||||
onDeepLink: (callback: (url: string) => void) => () => void;
|
||||
onQuickAskText: (callback: (text: string) => void) => () => void;
|
||||
getQuickAskText: () => Promise<string>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue