I have editor where I want to check if it's html tag then present tags autocomplete and if its attribute do the same with list of attributes. I haven't found any reliable way to find if text at cursor is at attribute or a tag. Below is what I currently have. But it gives me problems as wxSTC_H_DEFAULT is called in many other places (PHP Code for example inside <?php for example) which makes it unreliable.
Is there simple and reliable way to check for HTML tags and attribute that am missing?
Sorry for old post, I could not type well in mobile phone
checking for Tag
Code: Select all
bool Editor::IsStyleHtmlTag()
{
int style = GetStyleAt(GetCurrentPos());
switch(style)
{
case wxSTC_H_ATTRIBUTE :
case wxSTC_H_ATTRIBUTEUNKNOWN :
case wxSTC_H_DOUBLESTRING :
case wxSTC_H_SINGLESTRING :
case wxSTC_H_TAG :
case wxSTC_H_TAGUNKNOWN :
case wxSTC_H_OTHER:
case wxSTC_H_DEFAULT :
return !IsStyleHtmlAttribute();
}
return false;
}
Code: Select all
bool Editor::IsStyleHtmlAttribute()
{
wxString allowed = "htm_html_xhtml_php";
if(!allowed.Contains(GetFileName().GetExt()))
return false;
int style = GetStyleAt(GetCurrentPos());
switch(style)
{
case wxSTC_H_ATTRIBUTE :
case wxSTC_H_ATTRIBUTEUNKNOWN :
case wxSTC_H_DOUBLESTRING :
case wxSTC_H_SINGLESTRING :
{
return true;
}
case wxSTC_H_TAG :
case wxSTC_H_TAGUNKNOWN :
case wxSTC_H_OTHER:
case wxSTC_H_DEFAULT :
{
wxString oldWordChars = GetWordChars();
SetWordChars(oldWordChars+"<>?");
int start = WordStartPosition(GetCurrentPos(), true);
int end = WordEndPosition(GetCurrentPos(), true);
wxString current = GetTextRange(start, end);
//restore word chars
SetWordChars(oldWordChars);
int currentWordStart = WordStartPosition(GetCurrentPos(), true);
if((!current.Contains("<?") && !current.Contains("<") && !current.Contains(">")) || current.IsEmpty())
return true;
else if(current.Contains(">") && GetTextRange(start, start+1)!="<")
return true;
}
}
return false;
}
S.