* Update the position of the file list * @param {HTMLElement} $parent
($parent)
| 432 | * @param {HTMLElement} $parent |
| 433 | */ |
| 434 | function updateFileList($parent) { |
| 435 | const pinnedCount = editorManager.files.filter((file) => file.pinned).length; |
| 436 | const children = [...$parent.children]; |
| 437 | const newFileList = []; |
| 438 | for (let el of children) { |
| 439 | for (let file of editorManager.files) { |
| 440 | if (file.tab === el) { |
| 441 | newFileList.push(file); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | editorManager.files = newFileList; |
| 448 | |
| 449 | const draggedFile = newFileList.find((file) => file.tab === $tab); |
| 450 | if (draggedFile) { |
| 451 | const draggedIndex = newFileList.indexOf(draggedFile); |
| 452 | let nextPinnedState; |
| 453 | |
| 454 | if (!draggedFile.pinned && draggedIndex < pinnedCount) { |
| 455 | nextPinnedState = true; |
| 456 | } else if (draggedFile.pinned && draggedIndex >= pinnedCount) { |
| 457 | nextPinnedState = false; |
| 458 | } |
| 459 | |
| 460 | if (nextPinnedState !== undefined) { |
| 461 | draggedFile.setPinnedState(nextPinnedState, { reorder: false }); |
| 462 | if (typeof editorManager.normalizePinnedTabOrder === "function") { |
| 463 | editorManager.normalizePinnedTabOrder(editorManager.files); |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Checks if the tab is going to scroll and returns the scroll value |