From a19732667442c4fb3fba120abafc3f023dbb6098 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 17 Jun 2024 18:11:30 +0200 Subject: [PATCH] Separate colors for "Highlight occurrences of selected text" (IJPL-45173) GitOrigin-RevId: c8ae757fb9ceb3db0a628e68bee990223e29a800 --- platform/editor-ui-api/api-dump-unreviewed.txt | 1 + .../openapi/editor/colors/EditorColors.java | 3 ++- .../resources/messages/OptionsBundle.properties | 1 + .../highlighting/BackgroundHighlighter.java | 8 ++++++-- .../src/DefaultColorSchemesManager.xml | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/platform/editor-ui-api/api-dump-unreviewed.txt b/platform/editor-ui-api/api-dump-unreviewed.txt index 374c3565dde4..409d5c0bd3aa 100644 --- a/platform/editor-ui-api/api-dump-unreviewed.txt +++ b/platform/editor-ui-api/api-dump-unreviewed.txt @@ -2181,6 +2181,7 @@ com.intellij.openapi.editor.colors.EditorColors - sf:FOLDED_TEXT_ATTRIBUTES:com.intellij.openapi.editor.colors.TextAttributesKey - sf:FOLDED_TEXT_BORDER_COLOR:com.intellij.openapi.editor.colors.ColorKey - sf:GUTTER_BACKGROUND:com.intellij.openapi.editor.colors.ColorKey +- sf:HIGHLIGHT_SELECTED_TEXT_ATTRIBUTES:com.intellij.openapi.editor.colors.TextAttributesKey - sf:IDENTIFIER_UNDER_CARET_ATTRIBUTES:com.intellij.openapi.editor.colors.TextAttributesKey - sf:IGNORED_ADDED_LINES_BORDER_COLOR:com.intellij.openapi.editor.colors.ColorKey - sf:IGNORED_DELETED_LINES_BORDER_COLOR:com.intellij.openapi.editor.colors.ColorKey diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColors.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColors.java index 7104016f1e16..21a4a66669f0 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColors.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColors.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.editor.colors; import com.intellij.lang.Language; @@ -56,6 +56,7 @@ public interface EditorColors { TextAttributesKey WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("WRITE_IDENTIFIER_UNDER_CARET_ATTRIBUTES"); TextAttributesKey TEXT_SEARCH_RESULT_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("TEXT_SEARCH_RESULT_ATTRIBUTES"); + TextAttributesKey HIGHLIGHT_SELECTED_TEXT_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("HIGHLIGHT_SELECTED_TEXT_ATTRIBUTES"); TextAttributesKey FOLDED_TEXT_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("FOLDED_TEXT_ATTRIBUTES"); ColorKey FOLDED_TEXT_BORDER_COLOR = ColorKey.createColorKey("FOLDED_TEXT_BORDER_COLOR"); diff --git a/platform/ide-core/resources/messages/OptionsBundle.properties b/platform/ide-core/resources/messages/OptionsBundle.properties index 5fc8d0ce13f8..6792233ed419 100644 --- a/platform/ide-core/resources/messages/OptionsBundle.properties +++ b/platform/ide-core/resources/messages/OptionsBundle.properties @@ -19,6 +19,7 @@ options.general.attribute.descriptor.deleted.text=Text//Deleted text options.general.attribute.descriptor.search.result=Search Results//Search result options.general.attribute.descriptor.search.result.write.access=Search Results//Search result (write access) options.general.attribute.descriptor.text.search.result=Search Results//Text search result +options.general.attribute.descriptor.highlight.selected.text=Search Results//Selected text highlighting options.general.attribute.descriptor.template.variable=Live Templates//Template Variable options.java.attribute.descriptor.keyword=Keyword diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java index c612c4fb613e..9c14ada49bf1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BackgroundHighlighter.java @@ -216,7 +216,7 @@ final class BackgroundHighlighter { count++; results.add(result); offset = result.getEndOffset(); - result = findManager.findString(sequence, offset, findModel, null); + result = findManager.findString(sequence, offset, findModel); } return results; }) @@ -230,7 +230,10 @@ final class BackgroundHighlighter { List highlighters = new ArrayList<>(); MarkupModel markupModel = editor.getMarkupModel(); for (FindResult result : results) { - highlighters.add(markupModel.addRangeHighlighter(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES, result.getStartOffset(), result.getEndOffset(), + int startOffset = result.getStartOffset(); + int endOffset = result.getEndOffset(); + if (startOffset == start && endOffset == end) continue; + highlighters.add(markupModel.addRangeHighlighter(EditorColors.HIGHLIGHT_SELECTED_TEXT_ATTRIBUTES, startOffset, endOffset, HighlightManagerImpl.OCCURRENCE_LAYER, HighlighterTargetArea.EXACT_RANGE)); } editor.putUserData(SELECTION_HIGHLIGHTS, highlighters); @@ -349,3 +352,4 @@ final class BackgroundHighlighter { private static final class HighlightSelectionKey {} } + diff --git a/platform/platform-resources/src/DefaultColorSchemesManager.xml b/platform/platform-resources/src/DefaultColorSchemesManager.xml index 47eb67b0548f..a0fe4ed5174e 100644 --- a/platform/platform-resources/src/DefaultColorSchemesManager.xml +++ b/platform/platform-resources/src/DefaultColorSchemesManager.xml @@ -713,6 +713,14 @@ + + +