Search in sources :

Example 1 with SoftWrapModel

use of com.intellij.openapi.editor.SoftWrapModel in project intellij-community by JetBrains.

the class SoftWrapHelper method isCaretAfterSoftWrap.

/**
   * Every soft wrap implies that multiple visual positions correspond to the same document offset. We can classify
   * such positions by the following criteria:
   * <pre>
   * <ul>
   *   <li>positions from visual line with soft wrap start;</li>
   *   <li>positions from visual line with soft wrap end;</li>
   * </ul>
   * </pre>
   * <p/>
   * This method allows to answer if caret offset of the given editor points to soft wrap and visual caret position
   * belongs to the visual line where soft wrap end is located.
   *
   * @return          <code>true</code> if caret offset of the given editor points to visual position that belongs to
   *                  visual line where soft wrap end is located
   */
public static boolean isCaretAfterSoftWrap(CaretImpl caret) {
    if (!caret.isUpToDate()) {
        return false;
    }
    EditorImpl editor = caret.getEditor();
    SoftWrapModel softWrapModel = editor.getSoftWrapModel();
    int offset = caret.getOffset();
    SoftWrap softWrap = softWrapModel.getSoftWrap(offset);
    if (softWrap == null) {
        return false;
    }
    VisualPosition afterWrapPosition = editor.offsetToVisualPosition(offset, false, false);
    VisualPosition caretPosition = caret.getVisualPosition();
    return caretPosition.line == afterWrapPosition.line && caretPosition.column <= afterWrapPosition.column;
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) SoftWrapModel(com.intellij.openapi.editor.SoftWrapModel) SoftWrap(com.intellij.openapi.editor.SoftWrap) VisualPosition(com.intellij.openapi.editor.VisualPosition)

Aggregations

SoftWrap (com.intellij.openapi.editor.SoftWrap)1 SoftWrapModel (com.intellij.openapi.editor.SoftWrapModel)1 VisualPosition (com.intellij.openapi.editor.VisualPosition)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1