Skip to content

Commit da9603c

Browse files
WIP: add Mod-k shortcut to open color picker in CSS files
1 parent 5129e12 commit da9603c

File tree

2 files changed

+26875
-58765
lines changed

2 files changed

+26875
-58765
lines changed

client/modules/IDE/components/Editor/stateUtils.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@ function getFileEmmetConfig(fileName) {
258258
}
259259
}
260260

261+
function openColorPickerWithKeyboard(view) {
262+
const picker = view.contentDOM.querySelector('input[type="color"]');
263+
264+
if (!picker || picker.disabled) {
265+
return false;
266+
}
267+
268+
picker.focus();
269+
270+
if (typeof picker.showPicker === 'function') {
271+
picker.showPicker();
272+
} else {
273+
picker.click();
274+
}
275+
276+
return true;
277+
}
278+
261279
// Extra custom keymaps.
262280
// TODO: We need to add sublime mappings + other missing extra mappings here.
263281
const extraKeymaps = [{ key: 'Tab', run: insertTab, shift: indentLess }];
@@ -291,13 +309,25 @@ export function createNewFileState(filename, document, settings) {
291309

292310
// Depending on the file mode, we have a different tidier function.
293311
const mode = getFileMode(filename);
294-
extraKeymaps.push({
295-
key: `Shift-Mod-F`,
312+
const fileExtraKeymaps = [...extraKeymaps];
313+
314+
fileExtraKeymaps.push({
315+
key: 'Mod-k',
316+
run: (view) => {
317+
if (mode !== 'css') {
318+
return false;
319+
}
320+
return openColorPickerWithKeyboard(view);
321+
}
322+
});
323+
324+
fileExtraKeymaps.push({
325+
key: 'Shift-Mod-F',
296326
run: (cmView) => tidyCodeWithPrettier(cmView, mode)
297327
});
298328

299329
const keymaps = [
300-
extraKeymaps,
330+
fileExtraKeymaps,
301331
closeBracketsKeymap,
302332
defaultKeymap,
303333
historyKeymap,

0 commit comments

Comments
 (0)