コード例 #1
0
 /** {@inheritDoc} */
 @Override
 public void apply(final Document document) {
   cursorOffset = document.getCursorOffset();
   for (final Change change : changes) {
     document.replace(change.getOffset(), change.getLength(), change.getText());
   }
   if (linkedEditor != null && linkedModeModel != null) {
     LinkedMode mode = linkedEditor.getLinkedMode();
     LinkedModel model = linkedEditor.createLinkedModel();
     if (linkedModeModel.getEscapePosition() != 0) {
       model.setEscapePosition(linkedModeModel.getEscapePosition());
     } else {
       model.setEscapePosition(cursorOffset);
     }
     List<LinkedModelGroup> groups = new ArrayList<>();
     for (LinkedPositionGroup positionGroup : linkedModeModel.getGroups()) {
       LinkedModelGroup group = linkedEditor.createLinkedGroup();
       LinkedData data = positionGroup.getData();
       if (data != null) {
         LinkedModelData modelData = linkedEditor.createLinkedModelData();
         modelData.setType("link");
         modelData.setValues(data.getValues());
         group.setData(modelData);
       }
       List<Position> positions = new ArrayList<>();
       for (Region region : positionGroup.getPositions()) {
         positions.add(new Position(region.getOffset(), region.getLength()));
       }
       group.setPositions(positions);
       groups.add(group);
     }
     model.setGroups(groups);
     mode.enterLinkedMode(model);
   }
 }
コード例 #2
0
 /** {@inheritDoc} */
 @Override
 public LinearRange getSelection(final Document document) {
   if (region == null) {
     // keep cursor location
     return LinearRange.createWithStart(cursorOffset).andLength(0);
   } else {
     return LinearRange.createWithStart(region.getOffset()).andLength(region.getLength());
   }
 }
コード例 #3
0
ファイル: MatchNode.java プロジェクト: mkuznyetsov/che
  @Override
  public void updatePresentation(@NotNull NodePresentation presentation) {
    SpanElement spanElement =
        Elements.createSpanElement(styles.styles().presentableTextContainer());

    SpanElement lineNumberElement = Elements.createSpanElement();
    lineNumberElement.setInnerHTML(
        String.valueOf(match.getMatchLineNumber() + 1) + ":&nbsp;&nbsp;&nbsp;");
    spanElement.appendChild(lineNumberElement);

    SpanElement textElement = Elements.createSpanElement();
    Region matchInLine = match.getMatchInLine();
    String matchedLine = match.getMatchedLine();
    if (matchedLine != null && matchInLine != null) {
      String startLine = matchedLine.substring(0, matchInLine.getOffset());
      textElement.appendChild(Elements.createTextNode(startLine));
      SpanElement highlightElement = Elements.createSpanElement(resources.css().searchMatch());
      highlightElement.setInnerText(
          matchedLine.substring(
              matchInLine.getOffset(), matchInLine.getOffset() + matchInLine.getLength()));
      textElement.appendChild(highlightElement);

      textElement.appendChild(
          Elements.createTextNode(
              matchedLine.substring(matchInLine.getOffset() + matchInLine.getLength())));
    } else {
      textElement.appendChild(Elements.createTextNode("Can't find sources"));
    }
    spanElement.appendChild(textElement);

    presentation.setPresentableIcon(resources.searchMatch());
    presentation.setUserElement((Element) spanElement);
  }