コード例 #1
0
 @Override
 public void setText(@NotNull CharSequence text) {
   String s = StringUtil.convertLineSeparators(text.toString());
   myChars = new char[s.length()];
   s.getChars(0, s.length(), myChars, 0);
   myString = new String(myChars);
   myLineSet = LineSet.createLineSet(myString);
 }
コード例 #2
0
 @Override
 public void setText(@NotNull CharSequence text) {
   synchronized (myLock) {
     LOG.assertTrue(text.toString().startsWith(myShreds.get(0).getPrefix()));
     LOG.assertTrue(text.toString().endsWith(myShreds.get(myShreds.size() - 1).getSuffix()));
     if (isOneLine()) {
       text = StringUtil.replace(text.toString(), "\n", "");
     }
     String[] changes = calculateMinEditSequence(text.toString());
     assert changes.length == myShreds.size();
     for (int i = 0; i < changes.length; i++) {
       String change = changes[i];
       if (change != null) {
         Segment hostRange = myShreds.get(i).getHostRangeMarker();
         if (hostRange == null) continue;
         myDelegate.replaceString(hostRange.getStartOffset(), hostRange.getEndOffset(), change);
       }
     }
   }
 }
コード例 #3
0
 @Override
 public void insertString(final int offset, @NotNull CharSequence s) {
   synchronized (myLock) {
     LOG.assertTrue(offset >= myShreds.get(0).getPrefix().length(), myShreds.get(0).getPrefix());
     LOG.assertTrue(
         offset <= getTextLength() - myShreds.get(myShreds.size() - 1).getSuffix().length(),
         myShreds.get(myShreds.size() - 1).getSuffix());
   }
   if (isOneLine()) {
     s = StringUtil.replace(s.toString(), "\n", "");
   }
   myDelegate.insertString(injectedToHost(offset), s);
 }
コード例 #4
0
  @Override
  public void replaceString(int startOffset, int endOffset, @NotNull CharSequence s) {
    if (isOneLine()) {
      s = StringUtil.replace(s.toString(), "\n", "");
    }

    final CharSequence chars = getCharsSequence();
    CharSequence toDelete = chars.subSequence(startOffset, endOffset);

    int perfixLength = StringUtil.commonPrefixLength(s, toDelete);
    int suffixLength =
        StringUtil.commonSuffixLength(
            toDelete.subSequence(perfixLength, toDelete.length()),
            s.subSequence(perfixLength, s.length()));
    startOffset += perfixLength;
    endOffset -= suffixLength;
    s = s.subSequence(perfixLength, s.length() - suffixLength);

    doReplaceString(startOffset, endOffset, s);
  }