aboutsummaryrefslogtreecommitdiffhomepage
path: root/complete.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-23 18:07:21 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-23 18:07:21 -0800
commitf6afddd94bd3f47e414033746d038c5b222b63a3 (patch)
tree14a9638d655bb424ded9d80f1d38787bb363adda /complete.cpp
parent9edf9ad2acb61a3d7e523c4903abda62655e45c9 (diff)
Fix for tab-completing arguments. Closes #1261
Diffstat (limited to 'complete.cpp')
-rw-r--r--complete.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/complete.cpp b/complete.cpp
index e5b77576..d38104dd 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -1847,9 +1847,13 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
parse_node_tree_t tree;
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, &tree, NULL);
+
+ /* Find the plain statement that contains the position. We have to backtrack past spaces (#1261). So this will be at either the last space character, or after the end of the string */
+ size_t adjusted_pos = pos;
+ while (adjusted_pos > 0 && cmd.at(adjusted_pos - 1) == L' ')
+ adjusted_pos--;
- /* Find the plain statement that contains the position */
- const parse_node_t *plain_statement = tree.find_node_matching_source_location(symbol_plain_statement, pos, NULL);
+ const parse_node_t *plain_statement = tree.find_node_matching_source_location(symbol_plain_statement, adjusted_pos, NULL);
if (plain_statement != NULL)
{
assert(plain_statement->has_source() && plain_statement->type == symbol_plain_statement);