-
Notifications
You must be signed in to change notification settings - Fork 49
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
quick hover #27
quick hover #27
Conversation
* Refactored some of the previous implementations into a pure static class, keeping the existing API intact. s* mall optimisation: use array instead of array list
New API for checking pseudo selectors (for quick hover) + analyzer refactoring
Great, thanks for the refactoring. I like it very much. Merged. |
Thanks for merging. There is a small bug that I just discovered now. I will send a PR soon. Also, there is a possibility for optimisation. When finding applicable rules, all selectors get added. For example, when finding applicable selectors for a div, p {
color: red
} then this rules gets added as it is. That is both, It would be a nice optimisation if only the final List<OrderedRule> nameRules = holder.get(HolderItem.ELEMENT, nameLC);
if (nameRules != null) {
// Trying not to add all of them
// candidates.addAll(nameRules);
for (OrderedRule nr: nameRules) {
ArrayList<CombinedSelector> matchingRules = new ArrayList<CombinedSelector>();
for (CombinedSelector cs: nr.getRule().getSelectors()) {
if (cs.getLastSelector().getElementName().equals(nameLC)) {
matchingRules.add(cs);
}
}
final int matchCount = matchingRules.size();
RuleSetImpl ruleSet = new RuleSetImpl(matchingRules.toArray(new CombinedSelector[matchCount]));
ruleSet.addAll(nr.getRule());
candidates.add(new OrderedRule(ruleSet, nr.getOrder()));
}
} However, the line Thanks. |
Btw, the bug is in the |
Good news: There is no bug in jStyleParser code. I was using it slightly wrong in the browser. (When the mouse hovers out of an element, I was changing the match condition and then calling |
For #17
API to get selectors that match a pseudo clause
I have created a new class called
AnalyserUtil
which is designed to be pure (state-less) class. The functions in this class are all declaredstatic
. There are only 4 public functions: getApplicableRules, getElementStyle, hasPseudoSelctor, hasPseudoSelectorForAncestor. The idea is that clients can use these functions efficiently, without necessarily storing / recreating an Analyser instance. They can choose to cache the intermediate results (such as the result of getApplicableRules).This has been done without modifying the existing APIs and verifying that all unit tests pass. I have also tested everything in gngr.
Minor cleanup
SelectorImpl.getPseudoElement