mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
[code] Logical and visual positions, offset
This commit is contained in:
parent
2d017152fb
commit
2ae2828aad
@ -33,6 +33,10 @@
|
|||||||
description="Illustrates how to plug an action in">
|
description="Illustrates how to plug an action in">
|
||||||
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
|
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
|
||||||
</action>
|
</action>
|
||||||
|
<action id="EditorBasics.LogicalPositionIllustration" class="org.jetbrains.plugins.editor.basics.EditorAreaIllustration" text="Caret Position"
|
||||||
|
description="Illustrates how editor area is organized">
|
||||||
|
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
|
||||||
|
</action>
|
||||||
</actions>
|
</actions>
|
||||||
|
|
||||||
</idea-plugin>
|
</idea-plugin>
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.jetbrains.plugins.editor.basics;
|
||||||
|
|
||||||
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||||
|
import com.intellij.openapi.editor.*;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.ui.Messages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Anna Bulenkova
|
||||||
|
*/
|
||||||
|
public class EditorAreaIllustration extends AnAction {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(AnActionEvent anActionEvent) {
|
||||||
|
final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
|
||||||
|
CaretModel caretModel = editor.getCaretModel();
|
||||||
|
LogicalPosition logicalPosition = caretModel.getLogicalPosition();
|
||||||
|
VisualPosition visualPosition = caretModel.getVisualPosition();
|
||||||
|
int offset = caretModel.getOffset();
|
||||||
|
Messages.showInfoMessage("Logical position: " + logicalPosition.toString() + "\n" +
|
||||||
|
"Visual position: " + visualPosition.toString() + "\n" +
|
||||||
|
"Offset: " + offset, "Caret Parameters Inside The Editor");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(AnActionEvent e) {
|
||||||
|
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||||
|
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||||
|
e.getPresentation().setVisible(project != null && editor != null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user