Repository: mito-ds/mito (language: python)

Issue:
CMD+A keyboard doesn't work in column header cell editor
**Works in formulas**
1. Open a cell editor that has a formula in it
2. Press CMD + A to select the entire formula to edit. 
3. It works. Nice

**Does not work in column headers**
1. Open a column header 
2. Press CMD + A to select the entire column header to change
3. It closes the cell editor and selects the entire sheet.


https://github.com/mito-ds/mito/assets/18709905/6b76915a-e00b-4a3a-8adb-8b237954907e




Discussion / hints:
This is an issue in the rename for dataframe headers as well. If you:
1. Open a dataframe header
2. Press Cmd + A to highlight it all

It highlights the sheet instead of the dataframe name.

Fix patch:
diff --git a/mitosheet/src/mito/types.tsx b/mitosheet/src/mito/types.tsx
index 922be785d..56ac9bfa3 100644
--- a/mitosheet/src/mito/types.tsx
+++ b/mitosheet/src/mito/types.tsx
@@ -818,7 +818,7 @@ export interface KeyBinding {
     metaKey?: boolean;
 }
 
-export interface KeyboardShorcut {
+export interface KeyboardShortcut {
     macKeyCombo: KeyBinding
     winKeyCombo: KeyBinding
     action: ActionEnum
@@ -828,6 +828,18 @@ export interface KeyboardShorcut {
     // the command registered to that ID in plugin.tsx.
     jupyterLabCommand?: string
 
+    /**
+     * Some keyboard shortcuts should only be triggered if the user is not in a text input. 
+     * For example. cmd+a should select the text in the input field, not select all the cells.
+     */
+    skipIfInTextInput?: boolean
+
+    /**
+     * Some keyboard shortcuts should only be triggered if the user does not have text selected.
+     * For example, cmd+c should copy the text in the input field, not copy the cells.
+     */
+    skipIfTextSelected?: boolean
+
     // For some keybindings (ex: cmd + y), we'd want to stop propagation
     // so that they don't open something in your browser
     preventDefaultAndStopPropagation?: boolean
diff --git a/mitosheet/src/mito/utils/keyboardShortcuts.tsx b/mitosheet/src/mito/utils/keyboardShortcuts.tsx
index 90f3645e7..32f9c7192 100644
--- a/mitosheet/src/mito/utils/keyboardShortcuts.tsx
+++ b/mitosheet/src/mito/utils/keyboardShortcuts.tsx
@@ -1,10 +1,10 @@
-import { ActionEnum, KeyboardShorcut } from "../types"
+import { ActionEnum, KeyboardShortcut } from "../types"
 import { Actions } from "./actions"
 
 /**
  * A list of all keyboard shortcuts in the app.
  */
-export const keyboardShortcuts: KeyboardShorcut[] = [
+export const keyboardShortcuts: KeyboardShortcut[] = [
     {
         macKeyCombo: {
             metaKey: true,
@@ -14,6 +14,8 @@ export const keyboardShortcuts: KeyboardShorcut[] = [
             ctrlKey: true,
             keys: ['c']
         },
+        skipIfInTextInput: true,
+        skipIfTextSelected: true,
         action: ActionEnum.Copy
     },
     {
@@ -86,6 +88,7 @@ export const keyboardShortcuts: KeyboardShorcut[] = [
             ctrlKey: true,
             keys: ['a']
         },
+        skipIfInTextInput: true,
         preventDefaultAndStopPropagation: true,
         action: ActionEnum.Select_All
     },
@@ -100,6 +103,7 @@ export const keyboardShortcuts: KeyboardShorcut[] = [
             // But Edge grabs focus when pressing ctrl+PageUp/PageDown (which is the Excel shortcut)
             keys: ['ArrowLeft']
         },
+        skipIfInTextInput: true,
         action: ActionEnum.Open_Previous_Sheet
     },
     {
@@ -113,6 +117,7 @@ export const keyboardShortcuts: KeyboardShorcut[] = [
             // But Edge grabs focus when pressing ctrl+PageUp/PageDown (which is the Excel shortcut)
             keys: ['ArrowRight']
         },
+        skipIfInTextInput: true,
         action: ActionEnum.Open_Next_Sheet
     },
     {
@@ -309,11 +314,19 @@ export const handleKeyboardShortcuts = (e: React.KeyboardEvent, actions: Actions
         return keyCombo.keys.includes(e.key);
     })
 
-    if (shortcut !== undefined && !actions.buildTimeActions[shortcut.action].isDisabled()) {
+    if (shortcut === undefined) {
+        return;
+    }
+    
+    const shortcutIsDisabled = actions.buildTimeActions[shortcut.action].isDisabled();
+    const isInTextInput = e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement;
+    const isTextSelected = document.getSelection()?.toString() !== '';
+
+    if (!shortcutIsDisabled && !(shortcut.skipIfInTextInput && isInTextInput) && !(shortcut.skipIfTextSelected && isTextSelected)) {
         actions.buildTimeActions[shortcut.action].actionFunction()
         if (shortcut.preventDefaultAndStopPropagation) {
             e.preventDefault();
             e.stopPropagation();
         }
     }
-}
+}
\ No newline at end of file


Test patch:
diff --git a/tests/streamlit_ui_tests/streamlit.spec.ts b/tests/streamlit_ui_tests/streamlit.spec.ts
index f4d0588c6..74b4e1252 100644
--- a/tests/streamlit_ui_tests/streamlit.spec.ts
+++ b/tests/streamlit_ui_tests/streamlit.spec.ts
@@ -449,4 +449,11 @@ test.describe('Keyboard Shortcuts', () => {
     await expect(mito.locator('#root')).toContainText('2000-01-02 00:00:00');
     await expect(mito.locator('#root')).toContainText('1961-12-29 00:00:00');
   });
+
+  test('Select All isn\'t triggered when column header is editing', async ({ page }) => {
+    const mito = await getMitoFrameWithTestCSV(page);
+    await mito.getByTitle('Column1').dblclick();
+    await page.keyboard.press('Control+a');
+    await expect(mito.locator('.endo-column-header-container-selected')).toHaveCount(1);
+  });
 });