if (selectionModel.hasSelection()) {
return ExplicitAction.DEFAULT;
}
DocumentParser parser = getParser();
// 1) Check we are not in block already.
ParseResult<CssState> parseResult = parser.getState(
CssState.class, selectionModel.getCursorPosition(), " ");
if (parseResult == null) {
return ExplicitAction.DEFAULT;
}
JsonArray<Token> tokens = parseResult.getTokens();
Preconditions.checkNotNull(tokens);
Preconditions.checkState(tokens.size() > 0);
CssToken lastToken = (CssToken) tokens.peek();
if ("{".equals(lastToken.getContext())) {
return ExplicitAction.DEFAULT;
}
// 2) Check we will enter block.
parseResult = parser.getState(CssState.class, selectionModel.getCursorPosition(), "{");
if (parseResult == null) {
return ExplicitAction.DEFAULT;
}
tokens = parseResult.getTokens();
Preconditions.checkNotNull(tokens);