actions for Emmet edit point navigation (WEB-362)

This commit is contained in:
Dennis Ushakov
2015-01-20 23:55:14 +03:00
parent 5f5c7e5538
commit 2b67868513
3 changed files with 73 additions and 0 deletions
@@ -97,6 +97,19 @@
text="Update tag with Emmet" description="Update existing HTML tag with Emmet abbreviation">
<add-to-group group-id="EditorLangPopupMenu" anchor="last"/>
</action>
<group id="GoToEditPointGroup">
<separator/>
<add-to-group group-id="GoToMenu" anchor="after" relative-to-action="GoToErrorGroup"/>
<action id="EmmetNextEditPoint" class="com.intellij.codeInsight.template.emmet.actions.GoToEditPointAction$Forward"
text="Next Emmet Edit Point" description="Go to next Emmet edit point">
</action>
<action id="EmmetPreviousEditPoint" class="com.intellij.codeInsight.template.emmet.actions.GoToEditPointAction$Backward"
text="Previous Emmet Edit Point" description="Go to previous Emmet edit point">
</action>
</group>
</group>
</actions>
</component>
@@ -87,6 +87,7 @@ public class EmmetEditPointUtil {
}
static boolean isApplicableFile(PsiFile file) {
if (file == null) return false;
for (Language language : file.getViewProvider().getLanguages()) {
if (language.isKindOf(XMLLanguage.INSTANCE)) return true;
}
@@ -0,0 +1,59 @@
/*
* Copyright 2000-2015 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.template.emmet.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
/**
* @author Dennis.Ushakov
*/
public abstract class GoToEditPointAction extends DumbAwareAction {
@Override
public void update(AnActionEvent e) {
final Editor editor = getEditor(e);
final PsiFile file = getFile(e);
final boolean isApplicable = editor != null && EmmetEditPointUtil.isApplicableFile(file);
e.getPresentation().setEnabledAndVisible(isApplicable);
}
private static PsiFile getFile(AnActionEvent e) {
return CommonDataKeys.PSI_FILE.getData(e.getDataContext());
}
private static Editor getEditor(AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
return editor != null ? InjectedLanguageUtil.getTopLevelEditor(editor) : null;
}
public static class Forward extends GoToEditPointAction {
@Override
public void actionPerformed(AnActionEvent e) {
EmmetEditPointUtil.moveForward(getEditor(e), getFile(e));
}
}
public static class Backward extends GoToEditPointAction {
@Override
public void actionPerformed(AnActionEvent e) {
EmmetEditPointUtil.moveBackward(getEditor(e), getFile(e));
}
}
}