use yew::prelude::*;
use crate::exprtk::{Cursor, Token};
pub fn highlight<'a>(cursor: &mut Cursor<'a>, token: Token<'a>, position: u32) -> Html {
cursor.txt = token.content();
let is_auto = cursor.is_autocomplete(position);
let is_break = matches!(token, Token::Break(_));
let is_overlap = cursor.is_error();
let result = match (is_auto, is_overlap, is_break) {
(true, true, false) => html! {
<span ref={cursor.noderef.clone()} class="error_highlight">{ token.to_html() }</span>
},
(false, true, false) => html! { <span class="error_highlight">{ token.to_html() }</span> },
(true, false, false) => {
html! { <span ref={cursor.noderef.clone()}>{ token.to_html() }</span> }
},
_ => token.to_html(),
};
if is_auto && matches!(token, Token::Symbol(_)) {
cursor.auto = Some(token.content().to_owned());
}
if matches!(token, Token::Break(_)) {
cursor.increment_line();
} else {
cursor.increment_column(token.content().len() as u32);
}
result
}