コード例 #1
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
 public void deleteLeft(final CursorPosition cursorAt) {
   final BlockToLineMapping mapping = findBlockFor(cursorAt.getLine());
   if (mapping == null || mapping.textBlock == null) {
     throw new IsisException("invalid block " + mapping + " for line " + cursorAt.getLine());
   }
   mapping.textBlock.deleteLeft(mapping.line, cursorAt.getCharacter());
 }
コード例 #2
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
  /** deletes the selected text */
  public void delete(final TextSelection selection) {
    final CursorPosition from = selection.from();
    final CursorPosition to = selection.to();

    final BlockToLineMapping fromMapping = findBlockFor(from.getLine());
    final int fromBlock = fromMapping.index;
    final int fromLine = fromMapping.line;
    final int fromCharacter = from.getCharacter();

    final BlockToLineMapping toMapping = findBlockFor(to.getLine());
    final int toBlock = toMapping.index;
    final int toLine = toMapping.line;
    final int toCharacter = to.getCharacter();

    if (fromBlock == toBlock) {
      final TextBlock block = (TextBlock) blocks.elementAt(fromBlock);
      block.delete(fromLine, fromCharacter, toLine, toCharacter);
    } else {
      TextBlock block = (TextBlock) blocks.elementAt(toBlock);
      block.deleteTo(toLine, toCharacter);

      block = (TextBlock) blocks.elementAt(fromBlock);
      block.deleteFrom(fromLine, fromCharacter);

      fromMapping.textBlock.join(toMapping.textBlock);
      blocks.removeElementAt(toMapping.index);

      for (int i = fromBlock + 1; i < toBlock; i++) {
        blocks.removeElementAt(i);
      }
    }
  }
コード例 #3
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
  public void insert(final CursorPosition cursorAt, final String characters) {
    Assert.assertNotNull(cursorAt);

    final BlockToLineMapping block = findBlockFor(cursorAt.getLine());

    Assert.assertNotNull("failed to get block for line " + cursorAt.getLine(), block);

    block.textBlock.insert(block.line, cursorAt.getCharacter(), characters);
  }
コード例 #4
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
  /** returns only the text that is selected */
  public String getText(final TextSelection selection) {
    final CursorPosition from = selection.from();
    final CursorPosition to = selection.to();

    final int line = from.getLine();
    String text = getText(line);
    if (from.getLine() == to.getLine()) {
      return text.substring(from.getCharacter(), to.getCharacter());

    } else {
      final StringBuffer str = new StringBuffer();
      str.append(text.substring(from.getCharacter()));
      for (int i = line + 1; i < line + (to.getLine() - from.getLine()); i++) {
        text = getText(i);
        str.append(text);
      }
      text = getText(line + (to.getLine() - from.getLine()));
      str.append(text.substring(0, to.getCharacter()));
      return str.toString();
    }
  }
コード例 #5
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
 public void deleteRight(final CursorPosition cursorAt) {
   final BlockToLineMapping mapping = findBlockFor(cursorAt.getLine());
   mapping.textBlock.deleteRight(mapping.line, cursorAt.getCharacter());
 }
コード例 #6
0
ファイル: TextContent.java プロジェクト: adamhoward/isis
 public void breakBlock(final CursorPosition cursorAt) {
   final BlockToLineMapping mapping = findBlockFor(cursorAt.getLine());
   final TextBlock newBlock = mapping.textBlock.splitAt(mapping.line, cursorAt.getCharacter());
   blocks.insertElementAt(newBlock, mapping.index + 1);
 }