@@ -258,6 +258,39 @@ function getFileEmmetConfig(fileName) {
258258 }
259259}
260260
261+ function getColorPickerAtSelection ( view ) {
262+ const { head } = view . state . selection . main ;
263+ const { node } = view . domAtPos ( head ) ;
264+
265+ const startEl =
266+ node . nodeType === Node . ELEMENT_NODE ? node : node . parentElement ;
267+
268+ const lineEl = startEl ?. closest ( '.cm-line' ) ;
269+
270+ return (
271+ lineEl ?. querySelector ( 'input[type="color"]:not(:disabled)' ) ||
272+ view . contentDOM . querySelector ( 'input[type="color"]:not(:disabled)' )
273+ ) ;
274+ }
275+
276+ function openColorPickerWithKeyboard ( view ) {
277+ const picker = getColorPickerAtSelection ( view ) ;
278+
279+ if ( ! picker || picker . disabled ) {
280+ return false ;
281+ }
282+
283+ picker . focus ( ) ;
284+
285+ if ( typeof picker . showPicker === 'function' ) {
286+ picker . showPicker ( ) ;
287+ } else {
288+ picker . click ( ) ;
289+ }
290+
291+ return true ;
292+ }
293+
261294// Extra custom keymaps.
262295// TODO: We need to add sublime mappings + other missing extra mappings here.
263296const extraKeymaps = [ { key : 'Tab' , run : insertTab , shift : indentLess } ] ;
@@ -291,13 +324,26 @@ export function createNewFileState(filename, document, settings) {
291324
292325 // Depending on the file mode, we have a different tidier function.
293326 const mode = getFileMode ( filename ) ;
294- extraKeymaps . push ( {
327+ const fileExtraKeymaps = [ ...extraKeymaps ] ;
328+
329+ fileExtraKeymaps . push ( {
330+ key : 'Mod-k' ,
331+ run : ( view ) => {
332+ if ( mode !== 'css' ) {
333+ return false ;
334+ }
335+
336+ return openColorPickerWithKeyboard ( view ) ;
337+ }
338+ } ) ;
339+
340+ fileExtraKeymaps . push ( {
295341 key : `Shift-Mod-F` ,
296342 run : ( cmView ) => tidyCodeWithPrettier ( cmView , mode )
297343 } ) ;
298344
299345 const keymaps = [
300- extraKeymaps ,
346+ fileExtraKeymaps ,
301347 closeBracketsKeymap ,
302348 defaultKeymap ,
303349 historyKeymap ,
0 commit comments