Verified Owner
Top Description Fields Constructors Methods
org.jabref.gui.bibtexhighlighter

public Class BibTeXHighlighter

extends Object
implements SyntaxDecorator
Class Inheritance
All Implemented Interfaces
jfx.incubator.scene.control.richtext.SyntaxDecorator
Annotations
@NullMarked
Imports
java.util.ArrayList, .List, .Map, .Optional, java.util.function.Supplier, org.jabref.gui.StateManager, org.jabref.gui.search.Highlighter, .SearchType, org.jabref.model.entry.field.Field, org.jabref.model.search.query.SearchQuery, org.jabref.model.util.Range, io.github.kusoroadeolu.veneer.BibTeXSyntaxHighlighter, .BibTeXSyntaxHighlighter.BibTeXHighlightRegion, jfx.incubator.scene.control.richtext.SyntaxDecorator, .TextPos, jfx.incubator.scene.control.richtext.model.CodeTextModel, .RichParagraph, org.jspecify.annotations.NullMarked

SyntaxDecorator that applies BibTeX syntax highlighting and search-term highlighting to the CodeArea used in org.jabref.gui.entryeditor.SourceTab.

Highlighting itself is delegated to the Veneer BibTeXSyntaxHighlighter, which computes highlight regions over the full source text. Since CodeArea builds one RichParagraph per line, this class:

Instances are stateful (they hold the last computed text/region cache) and are intended to be long-lived, one per CodeArea, rather than recreated per paragraph.

Field Summary

Modifier and TypeField and Description
private String
private volatile boolean
private List<BibTeXSyntaxHighlighter.BibTeXHighlightRegion>
private Supplier<Map<Field, Range>>
private int[]
private final StateManager
private final BibTeXSyntaxHighlighter

Constructor Summary

AccessConstructor and Description
public
BibTeXHighlighter(StateManager
used to retrieve the active search query for term highlighting
stateManager
,
BibTeXSyntaxHighlighter
the syntax highlighter used to compute highlight regions for BibTeX source code
syntaxHighlighter
)

Creates a new highlighter.

Method Summary

Modifier and TypeMethod and Description
private void
addSearchHighlights(RichParagraph.Builder builder, String text, List<Range> matches)

Adds background highlight rectangles for matches in the current line.

private void
addSegmentWithSearchCheck(RichParagraph.Builder builder, String segmentText, int segmentStart, @Nullable String baseStyleClass, List<Range> matches)

Helper to add a text segment, splitting it if it intersects with search matches.

private void
addSyntaxSegments(RichParagraph.Builder
the paragraph builder to append segments to
builder
,
String
the plain text of the current line
text
,
int
the offset of this line's first character within the full cached text
lineStart
,
List<Range>
list of active search match ranges within this line
matches
)

Adds the syntax-highlighted segments for the given line to the builder, translating each cached BibTeXHighlightRegion (expressed in offsets over the full document) into offsets local to this line, and splitting segments if they overlap with search matches.

private void
appendSegment(RichParagraph.Builder builder, String text, @Nullable String baseStyleClass, boolean isSearchMatch)

public RichParagraph

Returns:

the styled RichParagraph for the requested line
createRichParagraph
(CodeTextModel
the code text model backing the CodeArea
model
,
int
the paragraph (line) index to render
index
)

Implements jfx.incubator.scene.control.richtext.SyntaxDecorator.createRichParagraph.

Builds the styled paragraph for a single line of the model, applying both BibTeX syntax highlighting and (if a search query is active) search-match highlighting.

private List<Range>
getSearchMatches(String text, int lineStart)

Finds search matches in the current line.

public void
handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom)

Implements jfx.incubator.scene.control.richtext.SyntaxDecorator.handleChange.

Marks the cache as dirty so that subsequent rendering calls will rebuild syntax highlight regions for the updated text model.

private void
refreshCacheIfNeeded(CodeTextModel
the code text model backing the CodeArea
model
)

Recomputes the highlight-region cache if the model's full text has changed since the last call or if the cache was invalidated by handleChange.

public void
setFieldPositionsProvider(Supplier<Map<Field, Range>>
supplier providing a mapping of fields to their global ranges
fieldPositionsProvider
)

Sets the provider for BibTeX field ranges within the source text.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedFullTextback to summary
private String cachedFullText
cacheDirtyback to summary
private volatile boolean cacheDirty
cachedRegionsback to summary
private List<BibTeXSyntaxHighlighter.BibTeXHighlightRegion> cachedRegions
fieldPositionsProviderback to summary
private Supplier<Map<Field, Range>> fieldPositionsProvider
lineStartsback to summary
private int[] lineStarts
stateManagerback to summary
private final StateManager stateManager
syntaxHighlighterback to summary
private final BibTeXSyntaxHighlighter syntaxHighlighter

Constructor Detail

BibTeXHighlighterback to summary
public BibTeXHighlighter(StateManager stateManager, BibTeXSyntaxHighlighter syntaxHighlighter)

Creates a new highlighter.

Parameters
stateManager:StateManager

used to retrieve the active search query for term highlighting

syntaxHighlighter:BibTeXSyntaxHighlighter

the syntax highlighter used to compute highlight regions for BibTeX source code

Method Detail

addSearchHighlightsback to summary
private void addSearchHighlights(RichParagraph.Builder builder, String text, List<Range> matches)

Adds background highlight rectangles for matches in the current line.

addSegmentWithSearchCheckback to summary
private void addSegmentWithSearchCheck(RichParagraph.Builder builder, String segmentText, int segmentStart, @Nullable String baseStyleClass, List<Range> matches)

Helper to add a text segment, splitting it if it intersects with search matches.

addSyntaxSegmentsback to summary
private void addSyntaxSegments(RichParagraph.Builder builder, String text, int lineStart, List<Range> matches)

Adds the syntax-highlighted segments for the given line to the builder, translating each cached BibTeXHighlightRegion (expressed in offsets over the full document) into offsets local to this line, and splitting segments if they overlap with search matches.

Parameters
builder:RichParagraph.Builder

the paragraph builder to append segments to

text:String

the plain text of the current line

lineStart:int

the offset of this line's first character within the full cached text

matches:List<Range>

list of active search match ranges within this line

appendSegmentback to summary
private void appendSegment(RichParagraph.Builder builder, String text, @Nullable String baseStyleClass, boolean isSearchMatch)
createRichParagraphback to summary
public RichParagraph createRichParagraph(CodeTextModel model, int index)

Implements jfx.incubator.scene.control.richtext.SyntaxDecorator.createRichParagraph.

Builds the styled paragraph for a single line of the model, applying both BibTeX syntax highlighting and (if a search query is active) search-match highlighting.

Parameters
model:CodeTextModel

the code text model backing the CodeArea

index:int

the paragraph (line) index to render

Returns:RichParagraph

the styled RichParagraph for the requested line

Annotations
@Override
getSearchMatchesback to summary
private List<Range> getSearchMatches(String text, int lineStart)

Finds search matches in the current line.

handleChangeback to summary
public void handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom)

Implements jfx.incubator.scene.control.richtext.SyntaxDecorator.handleChange.

Marks the cache as dirty so that subsequent rendering calls will rebuild syntax highlight regions for the updated text model.

Annotations
@Override
refreshCacheIfNeededback to summary
private void refreshCacheIfNeeded(CodeTextModel model)

Recomputes the highlight-region cache if the model's full text has changed since the last call or if the cache was invalidated by handleChange.

Parameters
model:CodeTextModel

the code text model backing the CodeArea

setFieldPositionsProviderback to summary
public void setFieldPositionsProvider(Supplier<Map<Field, Range>> fieldPositionsProvider)

Sets the provider for BibTeX field ranges within the source text.

Parameters
fieldPositionsProvider:Supplier<Map<Field, Range>>

supplier providing a mapping of fields to their global ranges