HTML auto complete in tag


#1

I am trying to have autocomplete fire automatically in HTML mode if certain conditions are met.

First is if a < brackets is typed, I accomplish this in the onkeyup handler like this.

var __Cursor = editor.getDoc().getCursor();
var __Token = editor.getTokenAt(__Cursor);
if (bAutoHintHtml) { bAuto = (__Token.string === ‘<’ && __Token.type === “tag bracket”) }

Which works perfectly. I then want to open autocomplete after a space inside of any HTML tag. I thought I could use

__Token.state.inTag but it is always null, or it is incorrect.

My question is, is there a sure fire way to know I am inside a tag?


#2

I solved this by opening autocomplete when the token type turned into “attribute”, which does what I wanted.

I have another question, reading some old codemirror post on github, I’ve been using onkeyup handler without a problem, inputread seems outdated, since I use contenteditable, does codemirror block onkeyup custom handlers?


#3

The xml completion demo also implements this, maybe you can get inspiration from that.