Skip to content

Commit add8933

Browse files
committed
feat: make the folder suggestion list scrollable
1 parent ab2a4d1 commit add8933

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ define(function (require, exports, module) {
922922
// then alphabetically by folder name, then by full path
923923
StringMatch.multiFieldSort(matches, { matchGoodness: 0, folderName: 1, label: 2 });
924924

925-
const topMatches = matches.slice(0, 5);
925+
const topMatches = matches.slice(0, 15);
926926
_renderFolderSuggestions(topMatches, $suggestions, $input);
927927
}
928928

@@ -938,33 +938,36 @@ define(function (require, exports, module) {
938938
function _registerFolderDialogInputHandlers($input, $suggestions, $dlg) {
939939
// keyboard navigation handler for arrow keys
940940
$input.on('keydown', function(e) {
941+
const isArrowDown = e.keyCode === 40;
942+
const isArrowUp = e.keyCode === 38;
943+
// we only want to handle the arrow up arrow down keys
944+
if (!isArrowDown && !isArrowUp) { return; }
945+
946+
e.preventDefault();
941947
const $items = $suggestions.find('.folder-suggestion-item');
942-
const $selected = $items.filter('.selected');
948+
if ($items.length === 0) { return; }
943949

944-
if (e.keyCode === 40) { // arrow down key
945-
e.preventDefault();
946-
if ($items.length === 0) { return; }
950+
const $selected = $items.filter('.selected');
947951

948-
if ($selected.length === 0) {
949-
$items.first().addClass('selected');
950-
} else {
951-
const currentIndex = $items.index($selected);
952-
$selected.removeClass('selected');
953-
const nextIndex = (currentIndex + 1) % $items.length;
954-
$items.eq(nextIndex).addClass('selected');
955-
}
956-
} else if (e.keyCode === 38) { // arrow up key
957-
e.preventDefault();
958-
if ($items.length === 0) { return; }
952+
// determine which item to select next
953+
let $nextItem;
954+
if ($selected.length === 0) {
955+
// no selection - select first or last based on direction
956+
$nextItem = isArrowDown ? $items.first() : $items.last();
957+
} else {
958+
// move selection
959+
const currentIndex = $items.index($selected);
960+
$selected.removeClass('selected');
961+
const nextIndex = isArrowDown
962+
? (currentIndex + 1) % $items.length
963+
: (currentIndex - 1 + $items.length) % $items.length;
964+
$nextItem = $items.eq(nextIndex);
965+
}
959966

960-
if ($selected.length === 0) {
961-
$items.last().addClass('selected');
962-
} else {
963-
const currentIndex = $items.index($selected);
964-
$selected.removeClass('selected');
965-
const nextIndex = (currentIndex - 1 + $items.length) % $items.length;
966-
$items.eq(nextIndex).addClass('selected');
967-
}
967+
// apply selection and scroll the selected item into view (if not in view)
968+
$nextItem.addClass('selected');
969+
if ($nextItem.length > 0) {
970+
$nextItem[0].scrollIntoView({ block: "nearest", behavior: "auto" });
968971
}
969972
});
970973

src/styles/brackets_patterns_override.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ code {
25302530
}
25312531

25322532
#folder-suggestions {
2533-
max-height: 180px;
2533+
max-height: 150px;
25342534
overflow-y: auto;
25352535
overflow-x: hidden;
25362536
border: 1px solid @bc-btn-border;

0 commit comments

Comments
 (0)