I’m currently embedding a customized DiffRequestPanel (with my own DiffRequestProcessor) within an Inlay Component.
Unfortunately, I’m unable to enable to user to use the Cmd+C shortcut to copy the displayed code they select within that panel.
I tried using this, but haven’t succeeded so far:
/** A JComponent in an Inlay Component does not properly capture Key Events. This fixes that. */
interface KeyboardAwareInlayComponent : KeyboardAwareFocusOwner {
override fun skipKeyEventDispatcher(ke: KeyEvent): Boolean = true
}
Is there something special I need to do for a DiffRequestPanel in this case?
Hard to know which one it is that I should try to apply this interface on.
The deepest child which seems to be where the text is living is the EditorComponentImpl that sits inside a JBScrollPane:
If it’s that component that is supposed to implement the interface, what is the suggested way to apply such a chance given how deeply ingrained this is?
@jeremibg you are right, the interface should be implemented by the component. Could you please try to apply it to the component returned by DiffRequestPanel#getComponent?
The precision about the diff panel being a component inlay was mostly to point out why I have to resort to using that KeyboardAwareFocusOwner interface, and why I’m unable to get it to work as expected to allow copying the content of the DiffPanel.
I already have my component added as a component inlay in the editor: that is not my issue.
I’m trying to understand on which of the components that compose a DiffRequestPanel I need to apply the KeyboardAwareFocusOwner interface to allow my users to copy-paste the displayed content.
InlayComponent
In case that can help, this is how I create and insert it:
val properties =
EditorEmbeddedComponentManager.Properties(
EditorEmbeddedComponentManager.ResizePolicy.any(),
null,
false,
true,
true,
true,
0,
editorContext.selectedOffsetStart) // always appear at top of selected context
val inlay = EditorEmbeddedComponentManager.getInstance().addComponent(editor, panel, properties)
The panel that is inserted is a JPanel which contains DiffRequestPanel#getComponent.
You can try yourself: you’ll see that even if the JComponent returned by DiffRequestPanel#getComponent implements KeyboardAwareFocusOwner correctly, the copy commands (Cmd+C) will not be registered appropriately.
@ilia.shulgin I tried using the exact example code snippet you used, and I personally still get the clipboard issue.
I wonder if it’s an IDE version issue.
Could you try to repro on:
Android Studio Koala | 2024.1.1
Build #AI-241.15989.150.2411.11948838, built on June 10, 2024
Runtime version: 17.0.11+1-b1207.24 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 15.3.2
Kotlin analyzer version: 2.0.0-ij241.15989-9
GC: G1 Young Generation, G1 Old Generation
Memory: 16384M
Cores: 16
Metal Rendering is ON
Registry:
ide.browser.jcef.osr.enabled=false
ide.browser.jcef.markdownView.osr.enabled=false
ide.browser.jcef.sandbox.enable=false
debugger.enable.memory.view=false
debugger.enable.overhead.monitor=false
projectView.showHierarchyErrors=false
performance.watcher.unresponsive.interval.ms=1000
idea.invalidate.caches.invalidates.vfs=true
light.edit.file.open.enabled=false
ide.experimental.ui=true
ide.slow.operations.assertion=false
ide.background.save.settings=false
Double-check
But just to make sure we’re aligned on the issue:
Insert a DiffRequestPanel inline as an inlay in an editor with EditorEmbeddedComponentManager#addComponent
Select the code that is displayed inside the DiffRequestPanel and try to copy it
In my case, what happens is that the copy command is not issued to the appropriate editor: it is the code in the original editor in which the inlay is embedded that gets highlighted and copied, not the code within the DiffRequest
Would you mind recording some screen cast to demonstrate what happens with the editor and diff in your case? I hope it helps us understand the issue better
if you don’t like to share it publicly here, please try the JetBrains Upload Service https://uploads.jetbrains.com/ and provide the Upload ID
After selecting text within the diff view, I press Cmd+C. This ends up selecting L46 (and copying it) in the original Editor because that is where my caret was when I inserted the Inlay.
I then place my caret focus back into the original Editor and press Cmd+V to show that the clipboard content is indeed L46, instead of being the text which I had selected and intended to copy from within the diff view.
(P.S. It seems like there isn’t a way to upload or embed a *.mov directly in here. I was essentially forced to go through https://uploads.jetbrains.com/)
Hi @akrasilnikov, I’m noticing the same clipboard issue using DiffRequestPanel on version AI-241. Interestingly, my custom plugin in AI-243, using the same exact plugin code for AI-241, does not have the same clipboard issues. Cmd+C will simply work in AI-243 without any changes. Are you aware of any changes made to DiffRequestPanel that could be causing these inconsistencies? I’ve looked though the commit history between idea/241.15989.150 to idea/243.22562.218 but have not seen anything that stands out. I’m hoping to fix this for AI-241 specifically since my team is not migrated over to the latest IDE version yet.