Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inline edit dialog #1039

Merged
merged 4 commits into from
Jan 15, 2025
Merged

Conversation

zeroliu
Copy link
Collaborator

@zeroliu zeroliu commented Jan 13, 2025

#1038

New Feature: Inline edit dialog/context menu

Enhanced built-in-prompt command with a new dialog view. Previously, commands such as "fix grammar", "summarize selection" will add the result to the chat view. It was not ideal because they are often unrelated to the ongoing chat. This change separates them from the chat experience and allows users to insert into the editor, replace selected text, or copy the text.

Screenshot 2025-01-13 at 12 44 27 AM

In addition, this change surfaces common commands in the context menu. Users can access them easily without finding them from the command list with cmd + p. The context menu item syncs with the command enable settings.

Screenshot 2025-01-13 at 12 44 44 AM

2025-01-12 23 52 23

Refactor: Commands

  • Moved all commands registration into one place.
  • Made Chat and main less cluttered.
  • Enforced all command registration to use const ID.
  • Mapped all command names to command IDs in one place.
  • Streamlined builtin-prompt command registration. They no longer need to live in Chat.tsx.

E2E Tests

  • Change command settings reflects to command list and context menu.
  • Summarize selection
  • Fix grammar
  • Simplify
  • Emojify
  • make selection longer
  • make selection shorter
  • translation
  • add custom prompts
  • delete custom prompts
  • apply custom prompts
  • apply ad-hoc custom prompts
  • force reindexing
  • clear local index
  • search orama
  • open chat window
  • toggle chat window
  • change tone
  • remove URL
  • explain like I'm 5
  • load conversation
  • list all index
  • generate glossary
  • count total token
  • count words and token of selection
  • rewrite as tweet / tweet thread
  • rewrite as press release
  • remove from index
  • generate TOC
  • gc index
  • inspect index

@zeroliu zeroliu force-pushed the zero/inline-edit-dialog branch from 8a738b5 to d7932bc Compare January 13, 2025 05:23
if (replace) {
editor.replaceRange(message, cursorFrom, cursorTo);
} else {
editor.replaceRange(message, cursorTo);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to cursorTo for insertion so when user selects text before insertion, it will add the text to the end of the selection, which is more intuitive.

name: "Change tone of selection",
},
},
enabledCommands: {},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change them to be true by default, so there is no need to list them explicitly. I kept the {enable: boolean} structure, so the current user settings will continue to work.

@zeroliu zeroliu force-pushed the zero/inline-edit-dialog branch 4 times, most recently from 38620e3 to a586c4b Compare January 13, 2025 08:30
this.registerEvent(
this.app.workspace.on("editor-menu", (menu: Menu, editor: Editor) => {
const selectedText = editor.getSelection().trim();
if (selectedText) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line keeps context menu clean when no text is selected

@@ -643,3 +533,31 @@ export function findCustomModel(modelKey: string, activeModels: CustomModel[]):
}
return model;
}

export async function insertIntoEditor(message: string, replace: boolean = false) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has no external dependency (can use global app). I move it to here as a standalone function so all components and modals can use it easily.

@zeroliu zeroliu force-pushed the zero/inline-edit-dialog branch from a586c4b to e32fa6f Compare January 13, 2025 09:22
@zeroliu zeroliu requested a review from logancyang January 13, 2025 09:23
@zeroliu zeroliu force-pushed the zero/inline-edit-dialog branch from e32fa6f to 6380d3b Compare January 14, 2025 07:10
Copy link
Owner

@logancyang logancyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff!!! I created the ticket to revamp these hardcoded prompts #1043 but not super high priority. Look forward to the user feedback. Let me know if this is ready to merge!

@logancyang logancyang merged commit 6f8861c into logancyang:master Jan 15, 2025
2 checks passed
@logancyang logancyang mentioned this pull request Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants