From 7985c77326f4850fafadd1d6c1fd0f8bd3e4043e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Dec 2018 09:33:03 -0500 Subject: Completion: ignore characters at and after point --- qpdf/qpdf.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index c86cb2a4..8c195373 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -371,7 +371,6 @@ class ArgParser std::string bash_prev; std::string bash_cur; std::string bash_line; - size_t bash_point; std::set completions; std::map* option_table; @@ -390,8 +389,7 @@ ArgParser::ArgParser(int argc, char* argv[], Options& o) : argv(argv), o(o), cur_arg(0), - bash_completion(false), - bash_point(0) + bash_completion(false) { option_table = &main_option_table; initOptionTable(); @@ -1989,8 +1987,9 @@ ArgParser::checkCompletion() int p = QUtil::string_to_int(bash_point_env.c_str()); if ((p > 0) && (p <= static_cast(bash_line.length()))) { - // Point to the last character - bash_point = static_cast(p) - 1; + // Truncate the line. We ignore everything at or after the + // cursor for completion purposes. + bash_line = bash_line.substr(0, p); } if (argc >= 4) { @@ -2215,7 +2214,7 @@ ArgParser::handleCompletion() if (bash_cur.empty() && (bash_prev.length() > 2) && (bash_prev.at(0) == '-') && (bash_prev.at(1) == '-') && - (bash_line.at(bash_point) == '=')) + (bash_line.at(bash_line.length() - 1) == '=')) { choice_option = bash_prev.substr(2, std::string::npos); } -- cgit v1.2.3-54-g00ecf