-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements #565: Highlighting matches works now also for regular expr…
…essions in preview panel and entry editor
- Loading branch information
1 parent
edcb399
commit 0bc1810
Showing
19 changed files
with
246 additions
and
215 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
import net.sf.jabref.gui.actions.Actions; | ||
import net.sf.jabref.gui.actions.PasteAction; | ||
import net.sf.jabref.gui.search.MatchesHighlighter; | ||
import net.sf.jabref.logic.search.SearchTextListener; | ||
import net.sf.jabref.logic.search.SearchQueryHighlightListener; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
|
@@ -35,11 +35,11 @@ | |
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class JTextAreaWithHighlighting extends JTextArea implements SearchTextListener { | ||
public class JTextAreaWithHighlighting extends JTextArea implements SearchQueryHighlightListener { | ||
|
||
private static final Log LOGGER = LogFactory.getLog(JTextAreaWithHighlighting.class); | ||
|
||
private List<String> wordsToHighlight; | ||
private Optional<Pattern> highlightPattern = Optional.empty(); | ||
|
||
private UndoManager undo; | ||
|
||
|
@@ -131,21 +131,20 @@ public void actionPerformed(ActionEvent evt) { | |
* | ||
* @param words to highlight | ||
*/ | ||
private void highLight(List<String> words) { | ||
private void highLight(Optional<Pattern> highlightPattern) { | ||
// highlight all characters that appear in charsToHighlight | ||
Highlighter highlighter = getHighlighter(); | ||
highlighter.removeAllHighlights(); | ||
|
||
if ((words == null) || words.isEmpty() || words.get(0).isEmpty()) { | ||
if (highlightPattern == null || !highlightPattern.isPresent()) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
simonharrer
Author
Contributor
|
||
return; | ||
} | ||
String content = getText(); | ||
if (content.isEmpty()) { | ||
return; | ||
} | ||
|
||
MatchesHighlighter.getPatternForWords(words, Globals.prefs.getBoolean(JabRefPreferences.SEARCH_REG_EXP), | ||
Globals.prefs.getBoolean(JabRefPreferences.SEARCH_CASE_SENSITIVE)).ifPresent(pattern -> { | ||
highlightPattern.ifPresent(pattern -> { | ||
Matcher matcher = pattern.matcher(content); | ||
while (matcher.find()) { | ||
try { | ||
|
@@ -157,23 +156,21 @@ private void highLight(List<String> words) { | |
} | ||
}); | ||
|
||
|
||
|
||
} | ||
|
||
@Override | ||
public void setText(String text) { | ||
super.setText(text); | ||
highLight(wordsToHighlight); | ||
highLight(highlightPattern); | ||
if (undo != null) { | ||
undo.discardAllEdits(); | ||
} | ||
} | ||
|
||
@Override | ||
public void searchText(List<String> words) { | ||
this.wordsToHighlight = words; | ||
highLight(words); | ||
public void highlightPattern(Optional<Pattern> highlightPattern) { | ||
this.highlightPattern = highlightPattern; | ||
highLight(highlightPattern); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
highlightPattern
is an Optional. Why is anull
check required?