X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/108c5fc82244a9f7bf31063cd0dbdb8216fb366e..5d7cc6d52918fbf09b9af24f6165961cae52836f:/Console.cpp diff --git a/Console.cpp b/Console.cpp index 91d389c..1afdb2f 100644 --- a/Console.cpp +++ b/Console.cpp @@ -141,7 +141,9 @@ static CYUTF8String Run(CYPool &pool, int client, CYUTF8String code) { json = NULL; #endif mode_ = Working; - if (json != NULL) + if (json == NULL) + size = 0; + else size = strlen(json); } else { mode_ = Sending; @@ -290,18 +292,19 @@ static char **Complete(const char *word, int start, int end) { _assert(false); } - std::string begin(prefix.str() + word); + std::string begin(prefix.str()); - driver.program_ = $ CYProgram($ CYExpress($C2(ParseExpression(pool, - " function(object, prefix) {\n" + driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression(pool, + " function(object, prefix, word) {\n" " var names = [];\n" - " var pattern = '^' + prefix;\n" + " var pattern = '^' + prefix + word;\n" + " var length = prefix.length;\n" " for (name in object)\n" " if (name.match(pattern) != null)\n" - " names.push(name);\n" + " names.push(name.substr(length));\n" " return names;\n" " }\n" - ), expression, $S(begin.c_str())))); + ), expression, $S(begin.c_str()), $S(word)))); driver.program_->Replace(context); @@ -333,7 +336,14 @@ static char **Complete(const char *word, int start, int end) { CYString *string(dynamic_cast(element->value_)); _assert(string != NULL); - std::string completion(string->value_, string->size_); + std::string completion; + if (string->size_ != 0) + completion.assign(string->value_, string->size_); + else if (driver.mode_ == CYDriver::AutoMessage) + completion = "]"; + else + continue; + completions.push_back(completion); if (!rest) { @@ -357,12 +367,6 @@ static char **Complete(const char *word, int start, int end) { if (count == 0) return NULL; - if (!common.empty()) { - size_t size(prefix.str().size()); - _assert(common.size() >= size); - common = common.substr(size); - } - size_t colon(common.find(':')); if (colon != std::string::npos) common = common.substr(0, colon + 1);