ExpressionContext context = createExpressionContext(start);
Result result = isQuick ? expressionNode.calculateQuickResult(context) : expressionNode.calculateResult(context);
- if (isQuick && result == null && !oldValue.isEmpty()) {
+ if (isQuick && result == null) {
+ if (!oldValue.isEmpty()) {
+ return;
+ }
+ }
+
+ final boolean resultIsNullOrEmpty = result == null || result.equalsToText("", element);
+
+ // do not update default value of neighbour segment
+ if (resultIsNullOrEmpty && myCurrentSegmentNumber >= 0 &&
+ (mySegments.getSegmentStart(segmentNumber) == mySegments.getSegmentEnd(myCurrentSegmentNumber) ||
+ mySegments.getSegmentEnd(segmentNumber) == mySegments.getSegmentStart(myCurrentSegmentNumber))) {
return;
}
- if (defaultValue != null && (result == null || result.equalsToText("", element))) {
+ if (defaultValue != null && resultIsNullOrEmpty) {
result = defaultValue.calculateResult(context);
}
if (element != null) {
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Formatter trims line that contains white spaces symbols only, however, there is a possible case that we want
- * to preserve them for particular line (e.g. for live template that defines blank line that contains $END$ marker).
+ * to preserve them for particular line
+ * (e.g. for live template that defines line with whitespaces that contains $END$ marker: templateText $END$).
* <p/>
* Current approach is to do the following:
* <pre>
* </pre>
* <p/>
* This method inserts that dummy comment (fallback to identifier <code>xxx</code>, see {@link CodeStyleManagerImpl#createDummy(PsiFile)})
- * if necessary (if target line contains white space symbols only).
+ * if necessary.
* <p/>
* <b>Note:</b> it's expected that the whole white space region that contains given offset is processed in a way that all
*/
@Nullable
public static TextRange insertNewLineIndentMarker(@NotNull PsiFile file, @NotNull Document document, int offset) {
- CharSequence text = document.getCharsSequence();
- if (offset < 0 || offset >= text.length() || !isWhiteSpaceSymbol(text.charAt(offset))) {
+ CharSequence text = document.getImmutableCharSequence();
+ if (offset <= 0 || offset >= text.length() || !isWhiteSpaceSymbol(text.charAt(offset))) {
return null;
}
-
- for (int i = offset - 1; i >= 0; i--) {
- char c = text.charAt(i);
- // We don't want to insert a marker if target line is not blank (doesn't consist from white space symbols only).
- if (c == '\n') {
- break;
- }
- if (!isWhiteSpaceSymbol(c)) {
- return null;
- }
+
+ if (!isWhiteSpaceSymbol(text.charAt(offset - 1))) {
+ return null; // no whitespaces before offset
}
int end = offset;
for (; end < text.length(); end++) {
+ if (text.charAt(end) == '\n') {
+ break; // line is empty till the end
+ }
if (!isWhiteSpaceSymbol(text.charAt(end))) {
- break;
+ return null;
}
}