mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
add summarize to context menu (#482)
This commit is contained in:
parent
dfb979b0cf
commit
e6e7a508e5
1 changed files with 28 additions and 1 deletions
29
src/main.ts
29
src/main.ts
|
|
@ -29,7 +29,7 @@ import {
|
|||
} from "@/utils";
|
||||
import VectorDBManager, { VectorStoreDocument } from "@/vectorDBManager";
|
||||
import { MD5 } from "crypto-js";
|
||||
import { Editor, Notice, Plugin, TFile, WorkspaceLeaf } from "obsidian";
|
||||
import { Editor, Notice, Plugin, TFile, WorkspaceLeaf, Menu } from "obsidian";
|
||||
import PouchDB from "pouchdb";
|
||||
|
||||
export default class CopilotPlugin extends Plugin {
|
||||
|
|
@ -446,6 +446,11 @@ export default class CopilotPlugin extends Plugin {
|
|||
new Notice("An error occurred while saving vault to vector store.");
|
||||
}
|
||||
}
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("editor-menu", this.handleContextMenu)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private getVaultIdentifier(): string {
|
||||
|
|
@ -699,6 +704,28 @@ export default class CopilotPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
handleContextMenu = (
|
||||
menu: Menu,
|
||||
editor: Editor
|
||||
): void => {
|
||||
this.addContextMenu(menu, editor, this);
|
||||
};
|
||||
|
||||
addContextMenu = (
|
||||
menu: Menu,
|
||||
editor: Editor,
|
||||
plugin: this,
|
||||
): void => {
|
||||
menu.addItem((item) => {
|
||||
item
|
||||
.setTitle("Copilot: Summarize Selection")
|
||||
.setIcon("bot")
|
||||
.onClick(async (e) => {
|
||||
plugin.processSelection(editor, "summarizeSelection");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getChainManagerParams(): LangChainParams {
|
||||
const {
|
||||
openAIApiKey,
|
||||
|
|
|
|||
Loading…
Reference in a new issue