Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to listen to the custom completion pop-up window, and when I select and press the enter event, I cannot listen with the following code. How can I solve this problem? #5730

Open
swanfly opened this issue Jan 28, 2025 · 0 comments

Comments

@swanfly
Copy link

swanfly commented Jan 28, 2025

Describe the bug

I want to listen to the custom completion pop-up window, and when I select and press the enter event, I cannot listen with the following code. How can I solve this problem?

Expected Behavior

the following code below

Current Behavior

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ace Editor Custom Completion</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.37.0/ace.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.37.0/ext-language_tools.min.js"></script>
    <style>
        #editor {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }
    </style>
</head>

<body>
<div id="editor"></div>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/chrome");
    editor.session.setMode("ace/mode/markdown");

    ace.require("ace/ext/language_tools");
    editor.setOptions({
        enableBasicAutocompletion: true,
        enableSnippets: true,
        enableLiveAutocompletion: true
    });

    var customCompleter = {
        getCompletions: function (editor, session, pos, prefix, callback) {
            var completions = [
                { name: "customFunction", value: "customFunction()", meta: "custom" },
                { name: "customVariable", value: "customVariable", meta: "custom" }
            ];
            callback(null, completions);
        }
    };

    editor.completers.push(customCompleter);
    editor.commands.addCommand({
        name: "customEnterCommand",
        bindKey: { win: "Enter", mac: "Enter" },
        exec: function (editor) {
            var cursor = editor.getCursorPosition();
            var line = editor.session.getLine(cursor.row);
            console.log("Current line text:", line);
            editor.session.insert({ row: cursor.row, column: line.length }, " - Added by custom command");
            editor.execCommand("newline");
        }
    });
</script>
</body>

</html>

Reproduction Steps

Complete prompt pops up, press enter, unable to execute the print code console.log("Current line text:", line);

Possible Solution

No response

Additional Information/Context

No response

Ace Version / Browser / OS / Keyboard layout

safari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants