Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from konifar/consider_size
Ellipsis too long strings
- Loading branch information
Showing
11 changed files
with
105 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/main/java/com/konifar/stringssearch/models/AbstractStringElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main.java.com.konifar.stringssearch.models; | ||
|
||
import com.intellij.navigation.ItemPresentation; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public abstract class AbstractStringElement implements StringElement { | ||
|
||
@Nullable | ||
public ItemPresentation getPresentation() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void navigate(boolean canNavigate) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public boolean canNavigate() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean canNavigateToSource() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public abstract String getName(); | ||
|
||
@Override | ||
public abstract String getTag(); | ||
|
||
@Override | ||
public abstract String getValue(); | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/konifar/stringssearch/models/NormalStringElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/konifar/stringssearch/models/QuantityStringElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/main/java/com/konifar/stringssearch/models/StringElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/konifar/stringssearch/search/StringEllipsisPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main.java.com.konifar.stringssearch.search; | ||
|
||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.codeStyle.MinusculeMatcher; | ||
import com.intellij.util.containers.FList; | ||
import com.intellij.util.text.Matcher; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
final class StringEllipsisPolicy { | ||
|
||
private static final int MAX_LENGTH = 100; | ||
|
||
private static final int ELLIPSIS_EXTRA_LENGTH = 20; | ||
|
||
private static final String DOTS = "..."; | ||
|
||
String ellipsizeText(@NotNull String text, Matcher matcher) { | ||
final int textLength = text.length(); | ||
|
||
if (textLength > MAX_LENGTH) { | ||
if (matcher instanceof MinusculeMatcher) { | ||
FList iterable = ((MinusculeMatcher) matcher).matchingFragments(text); | ||
if (iterable != null) { | ||
TextRange textRange = (TextRange) iterable.getHead(); | ||
int startOffset = textRange.getStartOffset(); | ||
|
||
int startIndex = 0; | ||
int endIndex = textLength; | ||
|
||
if (startOffset > ELLIPSIS_EXTRA_LENGTH) { | ||
startIndex = startOffset - ELLIPSIS_EXTRA_LENGTH; | ||
} | ||
if (textLength > startIndex + MAX_LENGTH) { | ||
endIndex = startIndex + MAX_LENGTH; | ||
} | ||
|
||
String ellipsizedText = text.substring(startIndex, endIndex); | ||
|
||
if (startIndex > 0) { | ||
ellipsizedText = DOTS + ellipsizedText; | ||
} | ||
if (endIndex < textLength) { | ||
ellipsizedText = ellipsizedText + DOTS; | ||
} | ||
|
||
return ellipsizedText; | ||
} | ||
} | ||
} | ||
|
||
return text; | ||
} | ||
|
||
} |