| 1596 | } |
| 1597 | |
| 1598 | bool ZepMode::HandleExCommand(std::string strCommand) { |
| 1599 | if (strCommand.empty()) |
| 1600 | return false; |
| 1601 | |
| 1602 | auto eraseExtKey = [](std::string& str) { |
| 1603 | auto pos = str.find_last_of('<'); |
| 1604 | if (pos != std::string::npos) { |
| 1605 | str.erase(pos, str.size() - pos); |
| 1606 | } |
| 1607 | }; |
| 1608 | |
| 1609 | if (m_lastKey == ExtKeys::BACKSPACE) { |
| 1610 | eraseExtKey(strCommand); |
| 1611 | |
| 1612 | // Remove the previous character |
| 1613 | if (!strCommand.empty()) |
| 1614 | strCommand.pop_back(); |
| 1615 | |
| 1616 | if (strCommand.empty()) { |
| 1617 | GetCurrentWindow()->SetBufferCursor(m_exCommandStartLocation); |
| 1618 | return true; |
| 1619 | } |
| 1620 | |
| 1621 | m_currentCommand = strCommand; |
| 1622 | return false; |
| 1623 | } |
| 1624 | |
| 1625 | if (m_lastKey == ExtKeys::ESCAPE) { |
| 1626 | GetCurrentWindow()->SetBufferCursor(m_exCommandStartLocation); |
| 1627 | return true; |
| 1628 | } |
| 1629 | |
| 1630 | if (m_lastKey == ExtKeys::RETURN) { |
| 1631 | assert(GetCurrentWindow()); |
| 1632 | |
| 1633 | auto& buffer = GetCurrentWindow()->GetBuffer(); |
| 1634 | auto bufferCursor = GetCurrentWindow()->GetBufferCursor(); |
| 1635 | |
| 1636 | if (strCommand[0] == '/' || strCommand[0] == '?') { |
| 1637 | // Just exit Ex mode when finished the search |
| 1638 | return true; |
| 1639 | } |
| 1640 | |
| 1641 | // Remove the return |
| 1642 | eraseExtKey(strCommand); |
| 1643 | if (strCommand == "") { |
| 1644 | return false; |
| 1645 | } |
| 1646 | |
| 1647 | if (GetEditor().Broadcast(std::make_shared<ZepMessage>(Msg::HandleCommand, strCommand))) { |
| 1648 | return true; |
| 1649 | } |
| 1650 | |
| 1651 | auto pCommand = GetEditor().FindExCommand(strCommand.substr(1)); |
| 1652 | if (pCommand) { |
| 1653 | auto strTok = string_split(strCommand, " "); |
| 1654 | pCommand->Run(strTok); |
| 1655 | } else if (strCommand == ":reg") { |
nothing calls this directly
no test coverage detected