@Override
  public VisualPosition processSoftWrap(@NotNull EditorPosition position, SoftWrap softWrap) {
    position.visualColumn = softWrap.getIndentInColumns();
    position.softWrapColumnDiff += softWrap.getIndentInColumns();

    if (position.logicalLine < myTargetLogical.line
        || position.logicalColumn != myTargetLogical.column) {
      return null;
    }
    return position.buildVisualPosition();
  }
Exemplo n.º 2
0
  public void testHomeProcessing() throws IOException {
    String text =
        "class Test {\n"
            + "    public String s = \"this is a long string literal that is expected to be soft-wrapped into multiple visual lines\";\n"
            + "}";

    init(30, text);
    myEditor.getCaretModel().moveToOffset(text.indexOf("}") - 1);

    List<? extends SoftWrap> softWraps =
        new ArrayList<SoftWrap>(getSoftWrapModel().getRegisteredSoftWraps());
    assertTrue(!softWraps.isEmpty());

    CaretModel caretModel = myEditor.getCaretModel();
    int expectedVisualLine = caretModel.getVisualPosition().line;
    while (!softWraps.isEmpty()) {
      SoftWrap softWrap = softWraps.get(softWraps.size() - 1);
      int caretOffsetBefore = caretModel.getOffset();

      home();

      // Expecting the caret to be moved at the nearest soft wrap start offset.
      int caretOffset = caretModel.getOffset();
      assertTrue(caretOffset < caretOffsetBefore);
      assertEquals(softWrap.getStart(), caretOffset);
      assertEquals(
          new VisualPosition(expectedVisualLine, softWrap.getIndentInColumns()),
          caretModel.getVisualPosition());

      // Expected that caret is moved to visual line start when it's located on soft wrap start
      // offset at the moment.
      home();
      assertEquals(softWrap.getStart(), caretModel.getOffset());
      assertEquals(new VisualPosition(expectedVisualLine, 0), caretModel.getVisualPosition());

      softWraps.remove(softWraps.size() - 1);
      expectedVisualLine--;
    }

    // Expecting caret to be located on the first non-white space symbol of non-soft wrapped line.
    home();
    assertEquals(text.indexOf("public"), caretModel.getOffset());
    assertEquals(
        new VisualPosition(expectedVisualLine, text.indexOf("public") - text.indexOf("{\n") - 2),
        caretModel.getVisualPosition());
  }