Skip to content

Commit

Permalink
Disable arrow keys if text area is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
taldekar committed Feb 5, 2025
1 parent b9d5bdc commit 20aee0b
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStoreKeys;
import software.aws.toolkits.eclipse.amazonq.lsp.AwsServerCapabiltiesProvider;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspStatusManager;
import software.aws.toolkits.eclipse.amazonq.lsp.model.ChatOptions;
import software.aws.toolkits.eclipse.amazonq.lsp.model.QuickActions;
import software.aws.toolkits.eclipse.amazonq.lsp.model.QuickActionsCommandGroup;
Expand Down Expand Up @@ -141,7 +142,7 @@ public final void onEvent(final AuthState authState) {
// chat view
if (browser != null && !browser.isDisposed() && !chatStateManager.hasPreservedState()) {
Optional<String> content = getContent();
if (!content.isPresent()) {
if (!content.isPresent() && !LspStatusManager.lspFailed()) {
canDisposeState = true;
ViewVisibilityManager.showChatAssetMissingView("update");
} else {
Expand Down Expand Up @@ -245,6 +246,38 @@ private String generateJS(final String jsEntrypoint) {
}
window.addEventListener('load', init);
window.addEventListener('load', () => {
const textarea = document.querySelector('textarea.mynah-chat-prompt-input');
if (textarea) {
textarea.addEventListener('keydown', (event) => {
const cursorPosition = textarea.selectionStart;
const hasText = textarea.value.length > 0;
// block arrow keys on empty text area
switch (event.key) {
case 'ArrowLeft':
if (!hasText || cursorPosition === 0) {
event.preventDefault();
event.stopPropagation();
return false;
}
break;
case 'ArrowRight':
if (!hasText || cursorPosition === textarea.value.length) {
event.preventDefault();
event.stopPropagation();
return false;
}
break;
default:
return true;
}
});
}
});
</script>
""", jsEntrypoint, getWaitFunction(), chatQuickActionConfig,
"true".equals(disclaimerAcknowledged));
Expand Down

0 comments on commit 20aee0b

Please sign in to comment.