/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.codeInsight.highlighting;

import com.intellij.find.FindManager;
import com.intellij.find.FindModel;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class EscapeHandler extends EditorActionHandler {
  private final EditorActionHandler myOriginalHandler;

  public EscapeHandler(EditorActionHandler originalHandler){
    myOriginalHandler = originalHandler;
  }

  @Override
  public void execute(@NotNull Editor editor, DataContext dataContext){
    editor.setHeaderComponent(null);

    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project != null) {
      HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(project);
      if (highlightManager != null && highlightManager.hideHighlights(editor, HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_ANY_KEY)) {

        StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
        if (statusBar != null) {
          statusBar.setInfo("");
        }

        FindManager findManager = FindManager.getInstance(project);
        if (findManager != null) {
          FindModel model = findManager.getFindNextModel(editor);
          if (model != null) {
            model.setSearchHighlighters(false);
            findManager.setFindNextModel(model);
          }
        }

        return;
      }
    }

    myOriginalHandler.execute(editor, dataContext);
  }

  @Override
  public boolean isEnabled(Editor editor, DataContext dataContext) {
    if (editor.hasHeaderComponent()) return true;
    Project project = CommonDataKeys.PROJECT.getData(dataContext);

    if (project != null) {
      HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(project);
      if (highlightManager != null) {
        Map<RangeHighlighter, HighlightManagerImpl.HighlightInfo> map = highlightManager.getHighlightInfoMap(editor, false);
        if (map != null) {
          for (HighlightManagerImpl.HighlightInfo info : map.values()) {
            if (!info.editor.equals(editor)) continue;
            if ((info.flags & HighlightManager.HIDE_BY_ESCAPE) != 0) {
              return true;
            }
          }
        }
      }
    }

    return myOriginalHandler.isEnabled(editor, dataContext);
  }
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -18,9 +18,9 @@
 -201
-3
+7
  Jet
@@ -36,566 +36,109 @@
 r.o.
-%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */
+ Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 %0Apac
@@ -367,16 +367,58 @@
 ontext;%0A
+import com.intellij.openapi.editor.Caret;%0A
 import c
@@ -1019,20 +1019,25 @@
 %0A  p
-ublic
+rotected
  void 
-e
+doE
 xecu
@@ -1054,32 +1054,45 @@
 l Editor editor,
+ Caret caret,
  DataContext dat
@@ -2029,32 +2029,39 @@
 .execute(editor,
+ caret,
  dataContext);%0A 
@@ -2106,22 +2106,61 @@
 bled
-(Editor editor
+ForCaret(@NotNull Editor editor, @NotNull Caret caret
 , Da
@@ -2949,16 +2949,23 @@
 (editor,
+ caret,
  dataCon

remove deprecated code usage in EscapeHandler