Added diagnostics.

This commit is contained in:
JohnHake 2019-07-30 15:02:11 -07:00
parent e14842981f
commit 038cc172a4
4 changed files with 17 additions and 20 deletions

View File

@ -7,6 +7,8 @@ import com.intellij.openapi.editor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import java.util.List;
/**
* @author Anna Bulenkova
*/
@ -15,14 +17,19 @@ public class EditorAreaIllustration extends AnAction {
public void actionPerformed(AnActionEvent anActionEvent) {
final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
CaretModel caretModel = editor.getCaretModel();
System.out.println("\n");
System.out.print("caretModel.isUpToDate: " + caretModel.isUpToDate() + ", ");
System.out.println("Number of carets: " + caretModel.getAllCarets().size());
Caret primary = caretModel.getPrimaryCaret();
System.out.println("Primary caret is valid? " + primary.isValid() + ", has: " + primary.getLogicalPosition().toString() + ", Offset: " + primary.getOffset());
LogicalPosition logicalPosition = caretModel.getLogicalPosition();
VisualPosition visualPosition = caretModel.getVisualPosition();
int offset = caretModel.getOffset();
Messages.showInfoMessage(logicalPosition.toString() + "\n" +
visualPosition.toString() + "\n" +
"Offset: " + offset
// TODO: Remove the next line of diagnostic code
+ "\n" + "LogicalPosition.leansForward = " + String.valueOf(logicalPosition.leansForward),
"Offset: " + offset,
"Caret Parameters Inside The Editor");
}

View File

@ -56,6 +56,7 @@
text="Caret Position"
description="Reports information about the caret position."
icon="EditorBasicsIcons.Sdk_default_icon">
<keyboard-shortcut keymap="$default" first-keystroke="control alt G"/>
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
</actions>

View File

@ -38,7 +38,7 @@ When a Document is opened the editor assigns an internal, zero-based coordinate
The first line in a Document and the first character in each line are assigned the zero position.
Note that the editor coordinate system is different from what is shown in the editor UI, which is one-based rather than zero-based.
[//]: # (TODO: Mention multiple carets, primary carets, single caret in Editor = primary caret)
<!-- TODO: Mention multiple carets, primary carets, single caret in Editor = primary caret -->
### 2.3.1. Caret Logical Position
The caret _Logical Position_ is a zero-based, (line and column) position of the caret in the Editor Tool Window.
@ -122,26 +122,15 @@ Column Position includes:
Tabs can occupy multiple columns, up to the tab size set for the editor.
* The character selected by the caret.
More specifically, the Logical Position of a caret represents the boundary between two characters.
The Logical Column Position of a caret represents the boundary between two characters.
As defined in the [LogicalPosition](upsource:///platform/editor-ui-api/src/com/intellij/openapi/editor/LogicalPosition.java) class, if a caret position is associated with a succeeding character it is said to _Lean Forward_.
[//]: # (TODO: Add an understandable definition for characters leaning forward. BOL leans, just before "space" does not.)
In the example below, placing a (red) line caret on the first visible character in Logical line three produces a **complete lack of lean forward?!**
**Only with caret color #FF0000 ?! The same color as for 'Unknown Symbol' in my Preferences \| Editor \| Color Scheme \| General**
[//]: # (TODO: Why does this not work for red line caret?)
![Caret Column Position - Line Caret](img/caret_col_pos_line.png){:width="800px"}
In the example below, placing a (blue) block caret on the first visible character in Logical line three produces a column position of 0 for both Visual and Logical Positions.
In both Visual and Logical Positions the character leans forward, meaning it is associated with the succeeding character in the Logical line.
[//]: # (TODO: Why does this seem to always return leans forward for a block caret?)
In the Logical Position the character leans forward, meaning it is associated with the succeeding character in the Logical line.
For the Visual Position the character is said to _Lean Right_, indicating its association with the succeeding character in the Visual line.
![Caret Column Position - Block Caret](img/caret_col_pos_block.png){:width="800px"}
### 2.3.4. Caret Offset
The _Offset_ of a caret is a character count from the beginning of a Document to the caret position.
Caret offsets are always calculated in terms of Logical Position.
@ -197,5 +186,5 @@ public class EditorAreaIllustration extends AnAction {
}
```
[//]: # (TODO: Add section with hints for reader to work with multiple carets.)
<!-- TODO: Add section with hints for reader to work with multiple carets. -->

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 KiB