feat: add ImagePasteAddon for clipboard image handling#143
Open
brianegan wants to merge 2 commits intocoder:mainfrom
Open
feat: add ImagePasteAddon for clipboard image handling#143brianegan wants to merge 2 commits intocoder:mainfrom
brianegan wants to merge 2 commits intocoder:mainfrom
Conversation
Image paste handling was baked into Terminal and InputHandler as a custom onImagePaste event, which doesn't exist in the xterm.js API. Extract it into an opt-in addon following the ITerminalAddon pattern (same as FitAddon) to keep the core Terminal API xterm.js-conformant. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Heya, really cool project! I was building a VSCode extension with ghostty-web and ran into the issue where I needed to paste images. I created this plugin with Claude Opus to handle such a case. Not sure if you're accepting submissions coauthored by AI, but if so, I've found this helpful and wanted to contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ImagePasteAddon, a new addon following theITerminalAddonpattern (same asFitAddon), that detects image data in clipboard paste events and emits them as base64-encoded payloads via anonImagePasteeventInputHandler.handlePasteto only claim paste events that contain text, allowing image-only pastes to bubble through to addonsTerminalAPI strictly xterm.js-conformant — no custom events on the Terminal classUsage
Design decisions
onImagePastedoesn't exist in xterm.js. Implementing it as an addon keeps the drop-in replacement promise intact — code written against the core API remains portable between xterm.js and ghostty-web.InputHandlerno longer callspreventDefault()/stopPropagation()at the top of paste handling. It only claims the event when there is text to process, letting image-only pastes reach addon listeners.ImagePasteAddonandIImagePasteDataare exported from the package entry point.Test plan
image-paste.test.tscovers activation, disposal, lifecycle, event subscription, image paste firing, non-image paste ignoring, and post-dispose cleanuponImagePastefiresonDatabehavior is unaffected🤖 Generated with Claude Code