<commit_before>// Copyright 2000-2019 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.largeFilesEditor;

import com.intellij.largeFilesEditor.actions.*;
import com.intellij.largeFilesEditor.editor.actions.LfeEditorActionTextStartEndHandler;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;

public class PlatformActionsReplacer {

  private static final Logger logger = Logger.getInstance(PlatformActionsReplacer.class);
  private static boolean isPlatformActionsWereAdapted = false;

  public static void makeAdaptingOfPlatformActionsIfNeed() {
    if (!isPlatformActionsWereAdapted) {
      isPlatformActionsWereAdapted = true;
      makeAdaptingOfPlatformActions();
    }
  }

  private static void makeAdaptingOfPlatformActions() {
    logger.info("[Large File Editor Subsystem] Performing adapting of platform actions...");

    disableActionForLfe(IdeActions.ACTION_HIGHLIGHT_USAGES_IN_FILE);
    disableActionForLfe("GotoLine");

    addEditorActionHandler(IdeActions.ACTION_FIND_NEXT, LfeEditorActionSearchAgainHandler::new);
    addEditorActionHandler(IdeActions.ACTION_FIND_PREVIOUS, LfeEditorActionSearchBackHandler::new);
    addEditorActionHandler(IdeActions.ACTION_EDITOR_TEXT_START,
                           origHandler -> {
                             return new LfeEditorActionTextStartEndHandler(origHandler, true);
                           });
    addEditorActionHandler(IdeActions.ACTION_EDITOR_TEXT_END,
                           origHandler -> {
                             return new LfeEditorActionTextStartEndHandler(origHandler, false);
                           });
    addEditorActionHandler(IdeActions.ACTION_EDITOR_ESCAPE, LfeEditorActionHandlerEscape::new);
    addEditorActionHandler(IdeActions.ACTION_FIND, LfeEditorActionHandlerFind::new);
    addDisablingEditorActionHandler(IdeActions.ACTION_REPLACE);
    addDisablingEditorActionHandler(IdeActions.ACTION_FIND_WORD_AT_CARET);
    addDisablingEditorActionHandler(IdeActions.ACTION_SELECT_ALL_OCCURRENCES);
    addDisablingEditorActionHandler(IdeActions.ACTION_SELECT_NEXT_OCCURENCE);
    addDisablingEditorActionHandler(IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE);
  }

  private static void addDisablingEditorActionHandler(String actionId) {
    addEditorActionHandler(actionId, LfeEditorActionHandlerDisabled::new);
  }

  private static void addEditorActionHandler(String actionId, MyEditorActionHandlerFactory lfeEditorActionHandlerFactory) {
    try {
      EditorActionManager editorActionManager = EditorActionManager.getInstance();
      EditorActionHandler originalHandler = editorActionManager.getActionHandler(actionId);
      EditorActionHandler newHandler = lfeEditorActionHandlerFactory.create(originalHandler);
      editorActionManager.setActionHandler(actionId, newHandler);<commit_msg>IDEA-CR-48853: IDEA-216265 IDEA-CR-48853 Review fixes2<commit_after>// Copyright 2000-2019 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.largeFilesEditor;

import com.intellij.largeFilesEditor.actions.*;
import com.intellij.largeFilesEditor.editor.actions.LfeEditorActionTextStartEndHandler;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;

public class PlatformActionsReplacer {

  private static final Logger logger = Logger.getInstance(PlatformActionsReplacer.class);
  private static boolean isPlatformActionsWereAdapted = false;

  public static void makeAdaptingOfPlatformActionsIfNeed() {
    if (!isPlatformActionsWereAdapted) {
      isPlatformActionsWereAdapted = true;
      makeAdaptingOfPlatformActions();
    }
  }

  private static void makeAdaptingOfPlatformActions() {
    logger.info("[Large File Editor Subsystem] Performing adapting of platform actions...");

    disableActionForLfe(IdeActions.ACTION_HIGHLIGHT_USAGES_IN_FILE);
    disableActionForLfe("GotoLine");

    addEditorActionHandler(IdeActions.ACTION_FIND_NEXT, LfeEditorActionSearchAgainHandler::new);
    addEditorActionHandler(IdeActions.ACTION_FIND_PREVIOUS, LfeEditorActionSearchBackHandler::new);
    addEditorActionHandler(IdeActions.ACTION_EDITOR_TEXT_START,
                           origHandler -> new LfeEditorActionTextStartEndHandler(origHandler, true));
    addEditorActionHandler(IdeActions.ACTION_EDITOR_TEXT_END,
                           origHandler -> new LfeEditorActionTextStartEndHandler(origHandler, false));
    addEditorActionHandler(IdeActions.ACTION_EDITOR_ESCAPE, LfeEditorActionHandlerEscape::new);
    addEditorActionHandler(IdeActions.ACTION_FIND, LfeEditorActionHandlerFind::new);
    addDisablingEditorActionHandler(IdeActions.ACTION_REPLACE);
    addDisablingEditorActionHandler(IdeActions.ACTION_FIND_WORD_AT_CARET);
    addDisablingEditorActionHandler(IdeActions.ACTION_SELECT_ALL_OCCURRENCES);
    addDisablingEditorActionHandler(IdeActions.ACTION_SELECT_NEXT_OCCURENCE);
    addDisablingEditorActionHandler(IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE);
  }

  private static void addDisablingEditorActionHandler(String actionId) {
    addEditorActionHandler(actionId, LfeEditorActionHandlerDisabled::new);
  }

  private static void addEditorActionHandler(String actionId, MyEditorActionHandlerFactory lfeEditorActionHandlerFactory) {
    try {
      EditorActionManager editorActionManager = EditorActionManager.getInstance();
      EditorActionHandler originalHandler = editorActionManager.getActionHandler(actionId);
      EditorActionHandler newHandler = lfeEditorActionHandlerFactory.create(originalHandler);
      editorActionManager.setActionHandler(actionId, newHandler);
{'fraction_non_alphanumeric': 0.06816372033763338, 'fraction_numerical': 0.00589265806657111, 'mean_word_length': 5.680851063829787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7663695', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1692, 'n_words': 265}