Codemirror: html-hint shows autocompletion suggestions on every letter

Created on 27 Jan 2017  路  4Comments  路  Source: codemirror/CodeMirror

Setup

Mode: htmlmixed
I wanted hint to show up automatically instead of a manual keyboard shortcut. So I have this:

cm.on('inputRead', function onChange(editor, input) {
 if (input.text[0] === ';' || input.text[0] === ' ') { return; }
 CodeMirror.commands.autocomplete(cm, null, { completeSingle: false })
});

Steps to reproduce

  • In a htmlmixed codemirror instance, type any letter
    Codemirror will show up the hint popup giving invalid suggestions. Also, while typing text content inside a tag, the popup shows up continuously.

screenshot 2017-01-28 01 20 48

Expected behavior

It should show tag/attribute suggestions only when writing a tag (after <) or inside a tag.

Most helpful comment

Yes. I wanted hint to show up automatically instead of a manual keyboard shortcut. So I have this:

cm.on('inputRead', function onChange(editor, input) {
 if (input.text[0] === ';' || input.text[0] === ' ') { return; }
 CodeMirror.commands.autocomplete(cm, null, { completeSingle: false })
});

Is this the right way to show automatic completion hints?

All 4 comments

The mode itself does not do any kind of completion, so you must be doing something in addition to setting the mode to htmlmixed.

Yes. I wanted hint to show up automatically instead of a manual keyboard shortcut. So I have this:

cm.on('inputRead', function onChange(editor, input) {
 if (input.text[0] === ';' || input.text[0] === ' ') { return; }
 CodeMirror.commands.autocomplete(cm, null, { completeSingle: false })
});

Is this the right way to show automatic completion hints?

Well, your code is popping up autocompletion on every character, so that's what you get. I'm not sure what you consider wrong about the suggestions in your screenshot, but they all appear to be valid tags there. If you want to only complete when the cursor is in a tag name or after a <, you'll have to program your completion logic that way.

I get it. Thanks @marijnh

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Azmisov picture Azmisov  路  4Comments

niftylettuce picture niftylettuce  路  4Comments

misterbeebee picture misterbeebee  路  4Comments

ellisonbg picture ellisonbg  路  4Comments

JoelEinbinder picture JoelEinbinder  路  5Comments