<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.actions

import com.intellij.codeInsight.daemon.impl.analysis.DefaultHighlightingSettingProvider
import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil
import com.intellij.codeInsight.documentation.render.DocRenderManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.impl.AppEditorFontOptions
import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.ex.util.EditorScrollingPositionKeeper
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDocumentManager
import com.intellij.xml.breadcrumbs.BreadcrumbsForceShownSettings
import com.intellij.xml.breadcrumbs.BreadcrumbsInitializingActivity

class BreadcrumbsReaderModeProvider : ReaderModeProvider {
  override fun applyModeChanged(project: Project,
                                editor: Editor,
                                readerMode: Boolean,
                                fileIsOpenAlready: Boolean,
                                preferGlobalSettings: Boolean) {
    val globalBreadcrumbsShown = EditorSettingsExternalizable.getInstance().isBreadcrumbsShown
    BreadcrumbsForceShownSettings.setForcedShown(
      when {
        preferGlobalSettings -> globalBreadcrumbsShown
        readerMode -> ReaderModeSettings.instance(project).showBreadcrumbs
        else -> globalBreadcrumbsShown
      }, editor)
    ApplicationManager.getApplication().invokeLater { BreadcrumbsInitializingActivity.reinitBreadcrumbsInAllEditors(project) }
  }
}

class HighlightingReaderModeProvider : ReaderModeProvider {
  override fun applyModeChanged(project: Project,
                                editor: Editor,
                                readerMode: Boolean,
                                fileIsOpenAlready: Boolean,
                                preferGlobalSettings: Boolean) {
    if (!fileIsOpenAlready) return

    val highlighting =
      if (readerMode && !ReaderModeSettings.instance(project).showWarnings) FileHighlightingSetting.SKIP_INSPECTION
      else FileHighlightingSetting.FORCE_HIGHLIGHTING

    HighlightLevelUtil.forceRootHighlighting(PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return, highlighting)
  }
}<commit_msg>IDEA-256658 IDEA-256801 Reader mode: respect breadcrumbs language settings<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.actions

import com.intellij.codeInsight.daemon.impl.analysis.DefaultHighlightingSettingProvider
import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil
import com.intellij.codeInsight.documentation.render.DocRenderManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.impl.AppEditorFontOptions
import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.ex.util.EditorScrollingPositionKeeper
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDocumentManager
import com.intellij.xml.breadcrumbs.BreadcrumbsForceShownSettings
import com.intellij.xml.breadcrumbs.BreadcrumbsInitializingActivity

class BreadcrumbsReaderModeProvider : ReaderModeProvider {
  override fun applyModeChanged(project: Project,
                                editor: Editor,
                                readerMode: Boolean,
                                fileIsOpenAlready: Boolean,
                                preferGlobalSettings: Boolean) {
    val language = PsiDocumentManager.getInstance(project).getPsiFile(editor.document)?.language ?: return
    val globalBreadcrumbsShown = EditorSettingsExternalizable.getInstance().isBreadcrumbsShownFor(language.id)
    BreadcrumbsForceShownSettings.setForcedShown(
      when {
        preferGlobalSettings -> globalBreadcrumbsShown
        readerMode -> ReaderModeSettings.instance(project).showBreadcrumbs
        else -> globalBreadcrumbsShown
      }, editor)
    ApplicationManager.getApplication().invokeLater { BreadcrumbsInitializingActivity.reinitBreadcrumbsInAllEditors(project) }
  }
}

class HighlightingReaderModeProvider : ReaderModeProvider {
  override fun applyModeChanged(project: Project,
                                editor: Editor,
                                readerMode: Boolean,
                                fileIsOpenAlready: Boolean,
                                preferGlobalSettings: Boolean) {
    if (!fileIsOpenAlready) return

    val highlighting =
      if (readerMode && !ReaderModeSettings.instance(project).showWarnings) FileHighlightingSetting.SKIP_INSPECTION
      else FileHighlightingSetting.FORCE_HIGHLIGHTING

    HighlightLevelUtil.forceRootHighlighting(PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return, highlighting)
  }
}
{'fraction_non_alphanumeric': 0.06710690701409959, 'fraction_numerical': 0.005711226128859539, 'mean_word_length': 3.7132043734230447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5220253', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1495, 'n_words': 243}