I’m implementing a feature that shows a gutter icon for file navigation on the top-level child elements of a file.
However, when I open a file in the editor while keeping the source preview pane (e.g. from the search window) open, the gutter icon gets displayed twice.
It seems like the LineMarkerProvider
is being triggered in both the editor and the preview pane, causing the icon to appear twice.
Is there any recommended way to detect and prevent this kind of duplicate gutter rendering? For example, by checking whether the same gutter icon is already shown before adding it again?
Below is the implementation of the gutter icon logic where the issue occurs.
SqlLineMakerProvider.kt
I have also tried avoiding duplicate gutter icons by checking the highlighting information associated with the file document, as shown below.
However, this approach doesn’t seem to work reliably.
val doc = e.containingFile.viewProvider.document
val identifier = e.firstChild ?: return
val daoFile = findDaoFile(project, file) ?: return
val daoMethod = findDaoMethod(e.containingFile, daoFile) ?: return
val modelEx = DocumentMarkupModel.forDocument(doc, project, false) as MarkupModelEx
val icon = getIcon(daoFile.toPsiFile(project))
val tooltip = getToolTipTitle(daoFile.toPsiFile(project))
val allHighlighters = modelEx.allHighlighters
val alreadyExists =
allHighlighters.any { highlighter ->
val renderer = highlighter.gutterIconRenderer
highlighter.document == doc &&
renderer != null &&
renderer.icon == icon &&
renderer.isNavigateAction == true &&
renderer.tooltipText?.contains(tooltip("")) == true
}
if (alreadyExists && allHighlighters.size > 1)return
Thank you.