Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

File tree now using numerical sort #754

Closed
paolieri opened this issue Mar 6, 2021 · 1 comment
Closed

File tree now using numerical sort #754

paolieri opened this issue Mar 6, 2021 · 1 comment

Comments

@paolieri
Copy link

paolieri commented Mar 6, 2021

Steps to Reproduce

  1. Create an empty project
  2. Create empty files called file_2ca.tex file_02d.tex file_2ea.tex

Expected Behaviour

The file names should be listed in alphabetical order, like ls or ls -1 | sort would show them:

file_02d.tex
file_2ca.tex
file_2ea.tex

Observed Behaviour

The file names are listed in "numerical alphabetical order":

image

This is the order that ls -1 | sort -n would use.

Context

When files have hex values in their name (e.g., hashes or checksums), this ordering is not reliable because initial 0's in the hex string are ignored.

Technical Info

The numerical file ordering is imposed by this source line in Overleaf:
/frontend/js/features/file-tree/components/file-tree-folder-list.js#L69

It appears that this pull request introduced this change in December 2020.

The problem is reproducible on any browser and appears to be the new intended behavior.

Analysis

There is nothing preventing the user from manually sorting these entries, for example by using this function:

function sortFileList(ul){
  var sorted = [];
  for (var i = ul.childNodes.length; i--;) {
    if (ul.childNodes[i].nodeName === 'LI')
      sorted.push(ul.childNodes[i]);
    }

    sorted.sort(function(a, b) {
      return b.getAttribute("aria-label") < a.getAttribute("aria-label");
    });

    var new_ul = ul.cloneNode(false);
    for(var i = 0; i < sorted.length; i++)
        new_ul.appendChild(sorted[i]);
    ul.parentNode.replaceChild(new_ul, ul);
}

sortFileList(document.getElementsByClassName('file-tree-list')[0]);

Afterward, the file list appears in the correct order:

image

It would be nice to give an option to the user, e.g., "Use numerical order in file tree".

@das7pad
Copy link
Member

das7pad commented Aug 6, 2021

Hi!

Thank you for taking the time to write up this issue.

We are in the process of migrating to a monorepo at https://github.com/overleaf/overleaf and will mark this repository read-only soon.
You can read more about the monorepo migration at overleaf/overleaf#923.

We are going to close this issue now to avoid any confusion about the inability to comment further.

If you believe this issue still needs addressing, please create a new issue at https://github.com/overleaf/overleaf.

Thanks again!

@das7pad das7pad closed this as completed Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants