summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/js.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/Userland/js.cpp b/Userland/js.cpp
index e1324e5b41..e06ea0d0bb 100644
--- a/Userland/js.cpp
+++ b/Userland/js.cpp
@@ -544,6 +544,9 @@ int main(int argc, char** argv)
};
auto complete = [&interpreter, &editor = *editor](const String& token) -> Vector<String> {
+ if (token.length() == 0)
+ return {}; // nyeh
+
StringView line { editor.buffer().data(), editor.cursor() };
// we're only going to complete either
// - <N>
@@ -556,23 +559,18 @@ int main(int argc, char** argv)
Function<void(const JS::Shape&, const StringView&)> list_all_properties = [&results, &list_all_properties](const JS::Shape& shape, auto& property_pattern) {
for (const auto& descriptor : shape.property_table()) {
if (descriptor.value.attributes & JS::Attribute::Enumerable) {
- if (descriptor.key.view().starts_with(property_pattern))
- if (!results.contains_slow(descriptor.key)) // hide duplicates
- results.append(descriptor.key);
+ if (descriptor.key.view().starts_with(property_pattern)) {
+ auto completion = descriptor.key;
+ if (!results.contains_slow(completion)) { // hide duplicates
+ results.append(completion);
+ }
+ }
}
}
if (const auto* prototype = shape.prototype()) {
list_all_properties(prototype->shape(), property_pattern);
}
};
- auto complete = [&results, &editor](auto& property_pattern) {
- if (results.size()) {
- auto completion = results.first().view();
- completion = completion.substring_view(property_pattern.length(), completion.length() - property_pattern.length());
- if (completion.length())
- editor.insert(completion);
- }
- };
if (token.contains(".")) {
auto parts = token.split('.', true);
@@ -597,12 +595,14 @@ int main(int argc, char** argv)
const auto* object = variable.to_object(interpreter->heap());
const auto& shape = object->shape();
list_all_properties(shape, property_pattern);
- complete(property_pattern);
+ if (results.size())
+ editor.suggest(property_pattern.length());
return results;
}
const auto& variable = interpreter->global_object();
list_all_properties(variable.shape(), token);
- complete(token);
+ if (results.size())
+ editor.suggest(token.length());
return results;
};
editor->on_tab_complete_first_token = [complete](auto& value) { return complete(value); };