summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-04-11 19:02:15 +0430
committerAndreas Kling <kling@serenityos.org>2020-04-11 17:15:19 +0200
commit2fdce695d6b3e7bbb1e6c05f12583e722771707f (patch)
treef9d26eb2d8c57054105699ec682105ad9ab81c67 /Userland
parentb59a391a7803692b1f3927238b0ba85bcc9669af (diff)
downloadserenity-2fdce695d6b3e7bbb1e6c05f12583e722771707f.zip
LibLine: Display suggestions and cycle between them
With extra color (tm) This commit also patches the users of LibLine to properly use the new API
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); };