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

When hitting "enter" to complete, enter is added to the document #8

Open
jwalton opened this issue Aug 14, 2018 · 4 comments
Open

When hitting "enter" to complete, enter is added to the document #8

jwalton opened this issue Aug 14, 2018 · 4 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@jwalton
Copy link

jwalton commented Aug 14, 2018

When completing a placeholder, if you type "enter", then a carriage return is added to the document being edited:

quill-bug

I'm trying to modify this module so I can use "{" as my trigger key, but then also use "}" as the end-key in addition to enter, that way you can just type {name} to insert the name placeholder. Only, as things stand, I end up inserting {name}} into the document.

@sotaan
Copy link
Contributor

sotaan commented Aug 20, 2018

Sorry for my late post, I was on vacation last week.

  1. I'll start looking up for the carriage return problem (it must be a small issue)
  2. I'd rather prefer that you create a PR implementing the other feature you want so I can guide you and help you make something production-ready both for you and me

@jwalton
Copy link
Author

jwalton commented Aug 20, 2018

I did this super hacky thing:

            // When '}' is pressed while autocomplete is suggesting,
            // accept the current suggestion.
            quill.keyboard.addBinding({
                key: 221,
                format: [ 'suggest' ],
                shiftKey: true
            }, this._quillCompleteSuggestion.bind(this));

    ...

    /**
     * Complete the currently displayed autocomplete suggestion.
     *
     * @returns {boolean} - false.  This prevents other keyboard bindings from
     *   running.
     */
    _quillCompleteSuggestion() {
        const autocomplete = this.quill.getModule('autocomplete');
        autocomplete.close(autocomplete.matchedPlaceholders[0]);
        return false;
    }

Which lets } close the tag, and also doesn't insert an extra }. At first I thought I could add a "endKey" to the config, and have it default to enter... But, this doesn't work for enter, because Quill already defines a keyboard shortcut for enter, and it returns false so this keyboard shortcut will never be run (unless you add it as part of the Quill config). -_- I'm very new to Quill, so I'm not sure if there's a much better way to do this. :P

@sotaan
Copy link
Contributor

sotaan commented Aug 20, 2018

I guess you are not using the last version of this module: it should be 1.0.7.
If not, please update before we continue discussing.
In your case, the last version bind some internal events differently in order to avoid some edge cases

@sotaan sotaan self-assigned this Aug 20, 2018
@sotaan sotaan added enhancement New feature or request help wanted Extra attention is needed question Further information is requested bug Something isn't working labels Aug 20, 2018
@jwalton
Copy link
Author

jwalton commented Aug 20, 2018

Yeah, I am using 1.0.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants