* prev switches the history pointer to the previous item. * The optional parameter prefix allows one to search the history selectively for commands that * start with a certain character sequence. * @param prefix - prefix string for searching backwards in history, empty string by default * @return true if the pointer was switched to an earlier item, false otherwise. */
| 1634 | * @return true if the pointer was switched to an earlier item, false otherwise. |
| 1635 | */ |
| 1636 | bool ConsoleHistory::prev(const QString& prefix) |
| 1637 | { |
| 1638 | bool wentPrev = false; |
| 1639 | |
| 1640 | // store prefix if it's the first history access |
| 1641 | if (_it == _history.cend()) { |
| 1642 | _prefix = prefix; |
| 1643 | } |
| 1644 | |
| 1645 | // while we didn't go back or reach history's begin ... |
| 1646 | while (!wentPrev && _it != _history.cbegin()) { |
| 1647 | // go back in history and check if item matches prefix |
| 1648 | // Skip empty items |
| 1649 | --_it; |
| 1650 | wentPrev = (!_it->isEmpty() && _it->startsWith(_prefix)); |
| 1651 | } |
| 1652 | return wentPrev; |
| 1653 | } |
| 1654 | |
| 1655 | bool ConsoleHistory::isEmpty() const |
| 1656 | { |
no test coverage detected