Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e724206b authored by Archie Pusaka's avatar Archie Pusaka
Browse files

floss: return the correct position for autocomplete

The function BtHelper::complete is supposed to return the position
of the current token, but currently it always returns 0.

Bug: 238572622
Tag: #floss
Test: Test these in btclient
      (1) a<Tab> => ad
                    adapter    advertise
      (2) adapter d<Tab> => adapter dis
                            disable    discoverable
      (3) adapter discov<Tab> => adapter discoverable

BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I22b551262656f0d5e8ad70cac428c799e26cd2a0
parent b5de90c4
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -56,23 +56,18 @@ impl Completer for BtHelper {
    ) -> Result<(usize, Vec<String>), ReadlineError> {
        let slice = &line[..pos];
        let candidates = self.get_candidates(slice.to_string().clone());
        let mut completions = candidates
            .iter()
            .map(|c| {
                if candidates.len() == 1 {
                    // If only one candidate, Completer will replace the input by
                    // the returned string. Return the complete string here to avoid
                    // input being replaced by the suggested word.
                    slice.to_string() + &c.suggest_word[c.matched_len..] + " "
                } else {
                    c.suggest_word.clone()
                }
            })
            .collect::<Vec<String>>();
        let mut completions =
            candidates.iter().map(|c| c.suggest_word.clone() + " ").collect::<Vec<String>>();

        completions.sort();

        Ok((0, completions))
        // |start| points to the starting position of the current token
        let start = match slice.rfind(' ') {
            Some(x) => x + 1,
            None => 0,
        };

        Ok((start, completions))
    }
}