Commit 07b94e9b authored by Francois Beaufort's avatar Francois Beaufort Committed by Commit Bot

serial: Order ports in chooser by file paths

This CL makes sure the list of ports visible in the serial port chooser
is ordered by file paths so that users can quickly jump to the desired
serial port.
It is especially useful when system has plenty of tty ports.

Screenshot: https://i.imgur.com/MoRcx5z.png

Bug: 884928
Change-Id: Ib0efe74eb2bd03263b7bf8e2fc6b8a719c839410
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2312316
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791456}
parent ffb607a7
...@@ -138,6 +138,12 @@ void SerialChooserController::OnPortManagerConnectionError() { ...@@ -138,6 +138,12 @@ void SerialChooserController::OnPortManagerConnectionError() {
void SerialChooserController::OnGetDevices( void SerialChooserController::OnGetDevices(
std::vector<device::mojom::SerialPortInfoPtr> ports) { std::vector<device::mojom::SerialPortInfoPtr> ports) {
// Sort ports by file paths.
std::sort(ports.begin(), ports.end(),
[](const auto& port1, const auto& port2) {
return port1->path.BaseName() < port2->path.BaseName();
});
for (auto& port : ports) { for (auto& port : ports) {
if (FilterMatchesAny(*port)) if (FilterMatchesAny(*port))
ports_.push_back(std::move(port)); ports_.push_back(std::move(port));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment