• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antonvw / wex / 17877007475

20 Sep 2025 07:22AM UTC coverage: 64.153% (+5.5%) from 58.646%
17877007475

push

github

antonvw
Merge branch 'develop'

18261 of 31235 branches covered (58.46%)

Branch coverage included in aggregate %.

14571 of 19943 relevant lines covered (73.06%)

1401.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.15
/src/ex/vi/command-parse.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
// Name:      command-parse.cpp
3
// Purpose:   Implementation of class wex::vi::parse_command
4
// Author:    Anton van Wezenbeek
5
// Copyright: (c) 2020-2025 Anton van Wezenbeek
6
////////////////////////////////////////////////////////////////////////////////
7

8
#include <wex/core/core.h>
9
#include <wex/ex/macros.h>
10
#include <wex/syntax/stc.h>
11
#include <wex/vi/vi.h>
12

13
#include "vim.h"
14

15
bool wex::vi::parse_command(std::string& command)
3,092✔
16
{
17
  if (const auto& it = get_macros().get_keys_map().find(command.front());
3,092✔
18
      it != get_macros().get_keys_map().end())
3,092✔
19
  {
20
    command = it->second;
1✔
21
  }
22

23
  if (
3,092✔
24
    m_command.type() != ex_command::type_t::FIND &&
6,184!
25
    m_command.type() != ex_command::type_t::FIND_MARGIN)
3,092!
26
  {
27
    m_count = 1;
3,092✔
28
  }
29

30
  // if this is a register, wait for next char for register name
31
  if (command.front() == '"')
3,092✔
32
  {
33
    if (command.size() < 2)
4!
34
    {
35
      return false;
×
36
    }
37
    set_register(command[1]);
4✔
38
    command.erase(0, 2);
4✔
39
    return true;
4✔
40
  }
41

42
  if (command.front() == ':')
3,088✔
43
  {
44
    return ex::command(command);
2,225✔
45
  }
46

47
  filter_count(command);
863✔
48

49
  if (command.empty())
863!
50
  {
51
    return false;
×
52
  }
53

54
  return parse_command_handle(command);
863✔
55
}
56

57
bool wex::vi::parse_command_handle(std::string& command)
863✔
58
{
59
  const motion_t motion      = get_motion(command);
863✔
60
  bool           check_other = true;
863✔
61

62
  if (command.size() == 1)
863✔
63
  {
64
    if (parse_command_handle_single(motion, command, check_other))
490✔
65
    {
66
      return true;
1✔
67
    }
68
  }
69
  else if (
373✔
70
    other_command(command) ||
662✔
71
    parse_command_motion(motion, command, check_other))
289✔
72
  {
73
    return true;
99✔
74
  }
75

76
  if (
763✔
77
    check_other && !motion_command(motion, command) && !other_command(command))
763✔
78
  {
79
    return false;
16✔
80
  }
81

82
  set_register(0);
747✔
83

84
  if (!command.empty())
747✔
85
  {
86
    if (m_mode.is_insert())
50✔
87
    {
88
      return insert_mode(command);
22✔
89
    }
90
    if (command != m_command_string)
28!
91
    {
92
      return parse_command(command);
28✔
93
    }
94

95
    return false;
×
96
  }
97

98
  return true;
697✔
99
}
100

101
bool wex::vi::parse_command_handle_single(
490✔
102
  motion_t     motion,
103
  std::string& command,
104
  bool&        check_other)
105
{
106
  if (
490✔
107
    (m_mode.is_visual() || command == "d") &&
317✔
108
    !get_stc()->get_selected_text().empty() &&
852!
109
    (motion == motion_t::CHANGE || motion == motion_t::DEL ||
45✔
110
     motion == motion_t::YANK))
111
  {
112
    if (motion == motion_t::CHANGE)
9✔
113
    {
114
      std::string s("i");
1✔
115
      m_mode.transition(s);
1✔
116
      command.erase(0, 1);
1✔
117
      return true;
1✔
118
    }
1✔
119

120
    command.erase(0, 1);
8✔
121
    m_mode_yank = m_mode.get();
8✔
122
    m_mode.escape();
8✔
123
  }
124
  else if (m_mode.transition(command))
481✔
125
  {
126
    check_other = false;
218✔
127
  }
128
  else
129
  {
130
    m_insert_command.clear();
263✔
131
  }
132

133
  return false;
489✔
134
}
135

136
bool wex::vi::parse_command_motion(
289✔
137
  motion_t     motion,
138
  std::string& command,
139
  bool&        check_other)
140
{
141
  if (wex::vim vim(this, command); vim.is_vim())
289✔
142
  {
143
    if (vim.other())
22✔
144
    {
145
      return true;
14✔
146
    }
147

148
    if (!vim.is_motion() && command.size() > 1)
8!
149
    {
150
      bell();
1✔
151
      command.clear();
1✔
152
      return true;
1✔
153
    }
154
  }
155
  else
156
  {
157
    switch (motion)
267!
158
    {
159
      case motion_t::CHANGE:
61✔
160
        m_mode.transition(command);
61✔
161
        break;
61✔
162

163
      case motion_t::DEL:
122✔
164
      case motion_t::YANK:
165
        command.erase(0, 1);
122✔
166
        break;
122✔
167

168
      case motion_t::NAVIGATE:
84✔
169
        if (m_mode.transition(command))
84✔
170
        {
171
          check_other = false;
20✔
172
        }
173
        else
174
        {
175
          m_insert_command.clear();
64✔
176
        }
177
        break;
84✔
178

179
      default:
×
180
        // do nothing
181
        break;
×
182
    }
183
  }
289✔
184

185
  return false;
274✔
186
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc