<commit_before>---
title: Editor Coordinate Systems - Caret Positions and Offsets
---

The previous tutorial [Working with Text](working_with_text.md) demonstrated how to use actions to access a caret placed in a document open in an editor. 
The examples replaced selected text in a document by using information about the caret.

Every caret has a set of properties describing its position in one of several coordinate systems. 
This tutorial describes how to access information about the caret(s) in an editor. 
The tutorial presents the following sections:
* bullet list
{:toc}

## Introduction
In this tutorial, the [editor_basics](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/editor_basics) code sample is used to explore caret positions. 
In particular, the **Caret Position** action added by `editor_basics` to the editor context menu is used to retrieve information about the current caret position. 
A keyboard shortcut can also initiate the action. 

![Editor Basics Menu](img/basics.png){:width="600px"}

The source code for the Java class behind the menu action is [EditorAreaIllustration.java](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java). 
The focus of discussion will be the `EditorAreaIllustration.actionPerformed()` method. 
For more information about creating action classes, see the [Actions Tutorial](/tutorials/action_system.md) which covers the topic in depth.

## Caret Positions from the CaretModel and Caret Objects
The properties of a caret can be accessed by obtaining an instance of the [CaretModel](upsource:///platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java) object. 
As in the [Working with Text](working_with_text.md) tutorial, the `AnActionEvent` is used to get the `Editor` object.<commit_msg>coordinates.md: cleanup link<commit_after>---
title: Editor Coordinate Systems - Caret Positions and Offsets
---

The previous tutorial [Working with Text](working_with_text.md) demonstrated how to use actions to access a caret placed in a document open in an editor. 
The examples replaced selected text in a document by using information about the caret.

Every caret has a set of properties describing its position in one of several coordinate systems. 
This tutorial describes how to access information about the caret(s) in an editor. 
The tutorial presents the following sections:
* bullet list
{:toc}

## Introduction
In this tutorial, the [editor_basics](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/editor_basics) code sample is used to explore caret positions. 
In particular, the **Caret Position** action added by `editor_basics` to the editor context menu is used to retrieve information about the current caret position. 
A keyboard shortcut can also initiate the action. 

![Editor Basics Menu](img/basics.png){:width="600px"}

The source code for the Java class behind the menu action is [EditorAreaIllustration](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java). 
The focus of discussion will be the `EditorAreaIllustration.actionPerformed()` method. 
For more information about creating action classes, see the [Actions Tutorial](/tutorials/action_system.md) which covers the topic in depth.

## Caret Positions from the CaretModel and Caret Objects
The properties of a caret can be accessed by obtaining an instance of the [CaretModel](upsource:///platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java) object. 
As in the [Working with Text](working_with_text.md) tutorial, the `AnActionEvent` is used to get the `Editor` object.
{'fraction_non_alphanumeric': 0.07592592592592592, 'fraction_numerical': 0.0015873015873015873, 'mean_word_length': 5.208538587848933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5620076', 'n_tokens_mistral': 1042, 'n_tokens_neox': 989, 'n_words': 425}