Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
74893be1
"git@developer.sourcefind.cn:chenpangpang/ComfyUI.git" did not exist on "57eea0efbb07a48d4810b477b29d44ba5425a742"
Commit
74893be1
authored
Apr 02, 2023
by
pythongosssss
Browse files
Added keyboard navigation + selection
parent
8a0a85e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
2 deletions
+62
-2
web/extensions/core/contextMenuFilter.js
web/extensions/core/contextMenuFilter.js
+62
-2
No files found.
web/extensions/core/contextMenuFilter.js
View file @
74893be1
...
@@ -25,13 +25,73 @@ app.registerExtension({
...
@@ -25,13 +25,73 @@ app.registerExtension({
filter
.
placeholder
=
"
Filter list
"
;
filter
.
placeholder
=
"
Filter list
"
;
this
.
root
.
prepend
(
filter
);
this
.
root
.
prepend
(
filter
);
let
selectedIndex
=
0
;
let
items
=
this
.
root
.
querySelectorAll
(
"
.litemenu-entry
"
);
let
itemCount
=
items
.
length
;
let
selectedItem
;
// Apply highlighting to the selected item
function
updateSelected
()
{
if
(
selectedItem
)
{
selectedItem
.
style
.
setProperty
(
"
background-color
"
,
""
);
selectedItem
.
style
.
setProperty
(
"
color
"
,
""
);
}
selectedItem
=
items
[
selectedIndex
];
if
(
selectedItem
)
{
selectedItem
.
style
.
setProperty
(
"
background-color
"
,
"
#ccc
"
,
"
important
"
);
selectedItem
.
style
.
setProperty
(
"
color
"
,
"
#000
"
,
"
important
"
);
}
}
updateSelected
();
// Arrow up/down to select items
filter
.
addEventListener
(
"
keydown
"
,
(
e
)
=>
{
if
(
e
.
key
===
"
ArrowUp
"
)
{
if
(
selectedIndex
===
0
)
{
selectedIndex
=
itemCount
-
1
;
}
else
{
selectedIndex
--
;
}
updateSelected
();
e
.
preventDefault
();
}
else
if
(
e
.
key
===
"
ArrowDown
"
)
{
if
(
selectedIndex
===
itemCount
-
1
)
{
selectedIndex
=
0
;
}
else
{
selectedIndex
++
;
}
updateSelected
();
e
.
preventDefault
();
}
else
if
((
selectedItem
&&
e
.
key
===
"
Enter
"
)
||
e
.
keyCode
===
13
||
e
.
keyCode
===
10
)
{
selectedItem
.
click
();
}
});
filter
.
addEventListener
(
"
input
"
,
()
=>
{
filter
.
addEventListener
(
"
input
"
,
()
=>
{
// Hide all items that dont match our filter
// Hide all items that dont match our filter
const
term
=
filter
.
value
.
toLocaleLowerCase
();
const
term
=
filter
.
value
.
toLocaleLowerCase
();
const
items
=
this
.
root
.
querySelectorAll
(
"
.litemenu-entry
"
);
items
=
this
.
root
.
querySelectorAll
(
"
.litemenu-entry
"
);
// When filtering recompute which items are visible for arrow up/down
// Try and maintain selection
let
visibleItems
=
[];
for
(
const
item
of
items
)
{
for
(
const
item
of
items
)
{
item
.
style
.
display
=
!
term
||
item
.
textContent
.
toLocaleLowerCase
().
includes
(
term
)
?
"
block
"
:
"
none
"
;
const
visible
=
!
term
||
item
.
textContent
.
toLocaleLowerCase
().
includes
(
term
);
if
(
visible
)
{
item
.
style
.
display
=
"
block
"
;
if
(
item
===
selectedItem
)
{
selectedIndex
=
visibleItems
.
length
;
}
visibleItems
.
push
(
item
);
}
else
{
item
.
style
.
display
=
"
none
"
;
if
(
item
===
selectedItem
)
{
selectedIndex
=
0
;
}
}
}
}
items
=
visibleItems
;
updateSelected
();
// If we have an event then we can try and position the list under the source
// If we have an event then we can try and position the list under the source
if
(
options
.
event
)
{
if
(
options
.
event
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment