Skip to content

Add space and move the cursor after drag and drop to empty prompt, ch… #387

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

Merged
merged 12 commits into from
Jul 8, 2025

Conversation

yzhangok
Copy link
Contributor

@yzhangok yzhangok commented Jul 2, 2025

…ange image icon and improve overlay removal's latency

Problem

This is to fix the issue found during bug bash

  1. The image icon looks different from other icon
  2. The latency of the removal of drag overlay is high
  3. When prompt input is empty, context added by drag&drop is not separated by empty space, and the cursor is not moving to the end of the input
  4. The images added by drag and drop sometimes are added to pinned context

Solution

  1. Use the right icon
Screenshot 2025-07-01 at 10 30 08 PM
  1. Force repaint before dispatch the event

  2. The insertContextToPosition is not able to handle the case when cursor position is 0, this is only happen in drag&drop, since customer does not need to type/click to trigger add context.

  3. This is reproducable when first click on @Pin Context, then does not select anything. Since the topBarTitleClick is still true in this case, the context added through drag&drop will be added to pinned context. Dispatch the event RESET_TOP_BAR_CLICKED (Renamed from CONTEXT_INSERTED) to reset the trigger source before add the context.

Tests

  • [ x ] I have tested this change on VSCode
  • I have tested this change on JetBrains
  • I have added/updated the documentation (if applicable)

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@yzhangok yzhangok requested a review from a team as a code owner July 2, 2025 06:32
laileni-aws
laileni-aws previously approved these changes Jul 2, 2025
Copy link
Collaborator

@laileni-aws laileni-aws left a comment

Choose a reason for hiding this comment

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

LGTM but this image looks odd to me in src/components/icon/icons/image.svg but looks good in PR description though.

One more observation: Icon is little up compared to Icon title in below screenshot.
Screenshot 2025-07-01 at 10 30 08 PM

@avi-alpert
Copy link
Collaborator

It seems like the drag & drop functionality in demo app is broken, this makes it hard for others to validate the functionality of this feature

Screen.Recording.2025-07-03.at.8.57.27.AM.mov

Copy link
Collaborator

@dogusata dogusata left a comment

Choose a reason for hiding this comment

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

I'm not fan of strictly defining the whole drag drop functionality just for images. This will cause duplication of code whenever we need different file types to be handled. However, you can do note it as a future TODO.

However, please avoid using hard coded strings for check statements. It is pretty open to mistakes. And not future proof. Please move the image string comparison to type. in the QuickActionCommand type definition command can be string | ImageCommandTypes which you can define. Then the consumer has to follow it.

MynahUITabsStore.getInstance().addListenerToDataStore(props.tabId, 'contextCommands', (contextCommands: QuickActionCommandGroup[]) => {
// Feature flag for image context command
this.imageContextFeatureEnabled = contextCommands?.some(group =>
group.commands.some((cmd: QuickActionCommand) => cmd.command.toLowerCase() === 'image')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still not fan of using static text comparisons, please avoid doing it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Define file type list if possible, since you can make the same thing for different file types in the future. I'm pretty sure that it will not be limited to image files in close future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If possible, grab them from config with their icons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the feature flags, will be removed after image context is launched in all IDEs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The IDE controls image-related functionality through the imageContextEnabled feature flag. When this flag is set to true, the language server adds the Image option to the available context types.

Users can add images to the context in Mynah UI through three methods:

  1. Using the context command menu
  2. Typing the @image: command
  3. Dragging and dropping images
    To maintain consistency, we've implemented a centralized feature flag that controls the visibility of all three image-adding methods. This ensures that image functionality is either entirely available or unavailable across for an IDE.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no imageContextEnabled feature flag thats controllable by a consumer, from what I can see in this PR you still depend on filtering contextCommands to see if image is in there, and thats how you set imageContextEnabled

@@ -193,72 +220,27 @@ export class ChatWrapper {
persistent: true,
events: {
dragenter: (e: DragEvent) => {
if (!this.hasImageContextCommand()) return;
if (!this.imageContextFeatureEnabled) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sill don't understand why we're strictly defining this feature for image, I still don't see it as a future proof implementation. What if we want to have more files in the future? Will we define everything one by one?

classNames: [ 'mynah-drag-overlay-content' ],
children: [
new Icon({ icon: MynahIcons.IMAGE }).render,
{ type: 'span', children: [ 'Add image to context' ] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

no text should be hardcoded, the string and icon should come from config, as Dogus pointed out in other comments

hardcoding it here means that the consumer has no control over what appears here. mynah-ui changes will be needed every time we want to change the string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -789,6 +790,7 @@ export interface ConfigOptions {
codeInsertToCursorEnabled?: boolean;
codeCopyToClipboardEnabled?: boolean;
test?: boolean;
dragOverlayIcon?: MynahIcons | MynahIconsType | CustomIcon;
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO: Please add documentation to CONFIG.md for these new fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will send followup pr to fix this

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah thats fine

@@ -66,6 +71,26 @@ export class ChatWrapper {
type: 'div',
classNames: [ 'mynah-chat-wrapper-header-spacer' ]
});

/*
The IDE controls image-related functionality through the imageContextEnabled feature flag.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is not true. You did not add an imageContextEnabled feature flag that the IDE can control. This PR sets imageContextEnabled based on whether an image command is included in the contextCommands

Please either fix the comment or preferably, fix the functionality and have it as a feature flag set in config

left: 0;
width: 100%;
height: 100%;
background: rgba(255,255,255,0.7);
Copy link
Collaborator

Choose a reason for hiding this comment

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

hardcoding colors is not allowed, you need to use variables (an existing one or add your own)

There are several reasons why we don't hardcode colors in mynah-ui, the main one being is this may break on different themes

flex-direction: column;
align-items: center;
z-index: 2;
font-size: 1.2em;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do not use hardcoded font size, use font size variable

align-items: center;
z-index: 2;
font-size: 1.2em;
color: #333;
Copy link
Collaborator

Choose a reason for hiding this comment

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

another hardcoded color

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Collaborator

@avi-alpert avi-alpert left a comment

Choose a reason for hiding this comment

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

I will approve to unblock launch - however please refer back to this PR's comments to be addressed in a follow up

@yzhangok yzhangok merged commit d6df339 into aws:main Jul 8, 2025
4 of 5 checks passed
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.

4 participants