-
Notifications
You must be signed in to change notification settings - Fork 51
added canvas support for pasted image in canvas #110
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @GuiLuan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request addresses an issue where the plugin couldn't handle pasted images in Obsidian Canvas files. The changes modify the getActiveFile
and renameFile
functions to correctly identify and handle Canvas files (which are of type TextFileView
). This ensures that image renaming works as expected within Canvas views, and that appropriate notifications are displayed.
Highlights
- Canvas Support: The plugin now supports renaming pasted images within Obsidian Canvas files.
- getActiveFile Modification: The
getActiveFile
function now checks forTextFileView
in addition toMarkdownView
to identify Canvas files. - renameFile Handling: The
renameFile
function now includes a conditional block to handle Canvas files, displaying a notification upon successful renaming.
Changelog
- src/main.ts
- Imported
TextFileView
from obsidian. - Modified
getActiveFile
to check forTextFileView
in addition toMarkdownView
. - Modified
renameFile
to handleTextFileView
(Canvas) files, displaying a rename notification.
- Imported
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
In canvas wide, an image sleeps,
Till paste awakes, and renaming peeps.
A file's new name,
A canvas's fame,
Obsidian's magic, secrets it keeps.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces canvas support for pasted images, modifying the getActiveFile
and renameFile
functions to accommodate TextFileView
(canvas). The changes seem reasonable, but let's review them in detail.
Summary of Findings
- Canvas file detection in
renameFile
: TherenameFile
function now includes a check for canvas files. It's important to ensure this check doesn't introduce unintended side effects or performance issues. - Active file detection: The
getActiveFile
function now checks for bothMarkdownView
andTextFileView
. This is a good change to support canvas files, but it's important to ensure that the order of these checks is correct and that the function returns the expected file type in all cases.
Merge Readiness
The pull request seems to address the intended functionality. However, I recommend addressing the comments below before merging to ensure code quality and prevent potential issues. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
if (!editor) { | ||
const view = this.app.workspace.getActiveViewOfType(TextFileView) | ||
if (view && view.file.extension === "canvas") { | ||
debugLog('Canvas file view detected', view.file.path) | ||
if (!this.settings.disableRenameNotice) { | ||
new Notice(`Renamed ${originName} to ${newName}`) | ||
} | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this canvas file check into a separate function for better readability and maintainability. This would also make it easier to test this specific logic.
Also, it might be useful to add a more specific check to ensure that the view
is actually a canvas view, and not just a TextFileView
with a .canvas
extension. This could prevent unexpected behavior if other TextFileView
types are introduced in the future.
if (!editor) {
if (this.isCanvasFileView(this.app.workspace.getActiveViewOfType(TextFileView))) {
debugLog('Canvas file view detected', view.file.path)
if (!this.settings.disableRenameNotice) {
new Notice(`Renamed ${originName} to ${newName}`)
}
return
}
debugLog('No active editor found')
new Notice(`Failed to rename ${newName}: no active editor`)
return
}
|
||
const editor = this.getActiveEditor() | ||
if (!editor) { | ||
const view = this.app.workspace.getActiveViewOfType(TextFileView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only modified the
getActiveFile
andrenameFile
functions, specifically, to allow returning when the view isTextFileView
(canvas is of typeTextFileView
).