Repository: ajaxorg/ace (JavaScript)

Issue:
Can't insert completions when executing command `startAutocomplete` with `matches` argument.
### Describe the bug

This might not be a bug and behaves as expected.

I am looking for a way to display suggestions like snippets independently of the current editor value and autocomplete filter logic.

I noticed that it is possible to run the following command to show any suggestions in the popover.
```
editor.execCommand('startAutocomplete', {
  matches: [
    { value: 'example value' },
  ],
});
```
But when I click on the suggestion, nothing happens.
This seems to be the case, because `this.completions` in the `autocomplete.js` is only defined when opening the popup, but not when clicking on the suggestion.

https://github.com/ajaxorg/ace/blob/master/src/autocomplete.js#L834

It would be possible to change the editor value by extending each object in `matches` with a completer
```
completer: {
  insertMatch: (editor, data) => {
    editor.setValue(data.value);
  },
}
```

but I am wondering if I am using the `startAutocomplete` command correctly and if it is intended for this use case.
I was also wondering if there is some kind of documentation for the commands and their arguments?



### Expected Behavior

When using the 'startAutocomplete' command with `matches`, it should be possible to insert a match when (for example) clicking on it.

### Current Behavior

See "Describe the bug".

### Reproduction Steps

I hope the code snippet in "Describe the bug" is sufficient.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### Ace Version / Browser / OS / Keyboard layout

Ace version 1.32.3


Discussion:

Patch:
diff --git a/src/autocomplete.js b/src/autocomplete.js
index d0aff0bce69..1ee896d390c 100644
--- a/src/autocomplete.js
+++ b/src/autocomplete.js
@@ -536,6 +536,7 @@ class Autocomplete {
             this.base = this.editor.session.doc.createAnchor(pos.row, pos.column);
             this.base.$insertRight = true;
             this.completions = new FilteredList(options.matches);
+            this.getCompletionProvider().completions = this.completions;
             return this.openPopup(this.editor, "", keepPopupPosition);
         }
 


Test patch:
diff --git a/src/autocomplete_test.js b/src/autocomplete_test.js
index 5852b17a942..eb03c76e8c7 100644
--- a/src/autocomplete_test.js
+++ b/src/autocomplete_test.js
@@ -1431,6 +1431,24 @@ module.exports = {
                 done();
             }, 100);
         }, 100);
+    },
+    "test: passing matches from execCommand": function() {
+        var editor = initEditor("");
+        editor.execCommand('startAutocomplete', {
+            matches: [
+                { value: 'example value' }
+            ]
+        });
+        user.type("\n");
+        
+        assert.equal(editor.getValue(), "example value");
+        
+        editor.resize(true);
+        editor.insertSnippet("<$1-${1|a1,b2,c3|}>");
+        user.type("Down");
+        user.type("\n");
+        
+        assert.equal(editor.getValue(), "example value<b2-b2>");
     }
 };
 
diff --git a/src/test/all_browser.js b/src/test/all_browser.js
index 0fbf4cee97d..b23ba6b48db 100644
--- a/src/test/all_browser.js
+++ b/src/test/all_browser.js
@@ -142,7 +142,7 @@ if (location.search) {
     else
         selectedTests = parts[0].split(",");
 }
-var filter = location.hash.substr(1);
+var filter = decodeURIComponent(location.hash.substr(1));
 window.onhashchange = function() { location.reload(); };
 
 require(selectedTests, function() {