Skip to content
Open
Changes from all 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
50 changes: 48 additions & 2 deletions client/modules/IDE/components/Editor/stateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,39 @@ function getFileEmmetConfig(fileName) {
}
}

function getColorPickerAtSelection(view) {
const { head } = view.state.selection.main;
const { node } = view.domAtPos(head);

const startEl =
node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;

const lineEl = startEl?.closest('.cm-line');

return (
lineEl?.querySelector('input[type="color"]:not(:disabled)') ||
view.contentDOM.querySelector('input[type="color"]:not(:disabled)')
);
}

function openColorPickerWithKeyboard(view) {
const picker = getColorPickerAtSelection(view);

if (!picker || picker.disabled) {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

getColorPickerAtSelection already filters out disabled inputs via :not(:disabled), but openColorPickerWithKeyboard checks picker.disabled again. Consider removing one of these checks (either allow disabled in the selector and keep the runtime check, or keep the selector and drop the redundant picker.disabled check) to avoid duplication.

Suggested change
if (!picker || picker.disabled) {
if (!picker) {

Copilot uses AI. Check for mistakes.
return false;
}

picker.focus();

if (typeof picker.showPicker === 'function') {
picker.showPicker();
} else {
picker.click();
}

return true;
}

// Extra custom keymaps.
// TODO: We need to add sublime mappings + other missing extra mappings here.
const extraKeymaps = [{ key: 'Tab', run: insertTab, shift: indentLess }];
Expand Down Expand Up @@ -291,13 +324,26 @@ export function createNewFileState(filename, document, settings) {

// Depending on the file mode, we have a different tidier function.
const mode = getFileMode(filename);
extraKeymaps.push({
const fileExtraKeymaps = [...extraKeymaps];

fileExtraKeymaps.push({
key: 'Mod-k',
run: (view) => {
if (mode !== 'css') {
return false;
}

return openColorPickerWithKeyboard(view);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

In CSS mode, this keybinding returns whatever openColorPickerWithKeyboard returns. When no picker is found it returns false, so the keypress will fall through to later keymaps (e.g. default bindings), which can cause unexpected behavior for users pressing Mod-K expecting “open color picker”. Consider always consuming Mod-K for CSS files (return true after attempting to open), and only return false for non-CSS files so other modes keep their default behavior.

Suggested change
return openColorPickerWithKeyboard(view);
// In CSS mode, always consume Mod-k after attempting to open the color picker
openColorPickerWithKeyboard(view);
return true;

Copilot uses AI. Check for mistakes.
}
});

fileExtraKeymaps.push({
key: `Shift-Mod-F`,
run: (cmView) => tidyCodeWithPrettier(cmView, mode)
});

const keymaps = [
extraKeymaps,
fileExtraKeymaps,
closeBracketsKeymap,
defaultKeymap,
historyKeymap,
Expand Down
Loading