Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix the issue that sometime image added via drag & drop are incorrectly routing to pinned contexts and drag overlay is not rendered"
Copy link
Contributor

@manodnyab manodnyab Jul 24, 2025

Choose a reason for hiding this comment

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

Suggested change
"description" : "Fix the issue that sometime image added via drag & drop are incorrectly routing to pinned contexts and drag overlay is not rendered"
"description" : "Fix the issue that sometime images added via drag & drop are incorrectly routed to pinned context"

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isCodeTrans
import software.aws.toolkits.resources.message
import java.awt.datatransfer.DataFlavor
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetDragEvent
import java.awt.dnd.DropTargetDropEvent
import java.awt.dnd.DropTargetEvent
import java.io.File
import java.util.concurrent.CompletableFuture
import javax.imageio.ImageIO.read
Expand Down Expand Up @@ -138,6 +140,39 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
// As an alternative, enabling the native drag in JCEF,
// and let the native handling the drop event, and update the UI through JS bridge.
val dropTarget = object : DropTarget() {
override fun dragEnter(dtde: DropTargetDragEvent) {
try {
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
Copy link
Contributor

Choose a reason for hiding this comment

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

can we extract this code out to a function since its the same code with one parameter changed?

"window.setDragAndDropVisible('true')",
browserInstance.jcefBrowser.cefBrowser.url,
0
)
} catch (e: Exception) {
LOG.error { "Failed to handle dragEnter: ${e.message}" }
}
}
override fun dragOver(dtde: DropTargetDragEvent) {
try {
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
"window.setDragAndDropVisible('true')",
browserInstance.jcefBrowser.cefBrowser.url,
0
)
} catch (e: Exception) {
LOG.error { "Failed to handle dragOver: ${e.message}" }
}
}
override fun dragExit(dte: DropTargetEvent) {
try {
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
"window.setDragAndDropVisible('false')",
browserInstance.jcefBrowser.cefBrowser.url,
0
)
} catch (e: Exception) {
LOG.error { "Failed to handle dragExit: ${e.message}" }
}
}
override fun drop(dtde: DropTargetDropEvent) {
try {
dtde.acceptDrop(dtde.dropAction)
Expand Down Expand Up @@ -166,6 +201,18 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
validImages.subList(20, validImages.size).clear()
}

browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
"window.resetTopBarClicked()",
browserInstance.jcefBrowser.cefBrowser.url,
0
)

browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
"window.setDragAndDropVisible('false')",
browserInstance.jcefBrowser.cefBrowser.url,
0
)

val json = OBJECT_MAPPER.writeValueAsString(validImages)
browserInstance.jcefBrowser.cefBrowser.executeJavaScript(
"window.handleNativeDrop('$json')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project)
})
});
};

window.setDragAndDropVisible = function(visibility) {
const parsedVisibility = JSON.parse(visibility);
qChat.setDragOverlayVisible(qChat.getSelectedTabId(), parsedVisibility)
};

window.resetTopBarClicked = function() {
qChat.resetTopBarClicked(qChat.getSelectedTabId())
};
}
</script>
""".trimIndent()
Expand Down
Loading