Java 类com.intellij.openapi.editor.event.DocumentEvent 实例源码

项目:greycat-idea-plugin    文件:GCMStructureViewModel.java   
public GCMStructureViewModel(@NotNull PsiFile psiFile, @NotNull final GCMStructureViewRootElement root, Editor editor) {
    super(psiFile, root);
    withSorters(typeSorter, Sorter.ALPHA_SORTER);
    editor.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent event) {
            synchronized (needRefresh) {
                needRefresh = true;
            }
        }
    });
    executor.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            GCMStructureViewModel.this.refreshView();
        }
    }, 15, 5, TimeUnit.SECONDS);

}
项目:tmc-intellij    文件:TextInputListener.java   
private String generatePatchDescription(
        DocumentEvent documentEvent, List<DiffMatchPatch.Patch> patches) {

    logger.info("Creating JSON from patches.");
    String source = documentEvent.getSource().toString();

    if (documentEvent.getSource().toString().length() <= 20) {
        return null;
    }

    source = source.substring(20, source.length() - 1);
    return JsonMaker.create()
            .add("file", new PathResolver().getPathRelativeToProject(source))
            .add("patches", diff.patch_toText(patches))
            .add(
                    "full_document",
                    documentEvent.getNewLength() == documentEvent.getDocument().getTextLength())
            .toString();
}
项目:ApiDebugger    文件:ResponseBodyWidget.java   
private Editor createEditor() {
    PsiFile myFile = null;
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document doc = myFile == null
            ? editorFactory.createDocument("")
            : PsiDocumentManager.getInstance(mProject).getDocument(myFile);
    Editor editor = editorFactory.createEditor(doc, mProject);
    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setFoldingOutlineShown(true);
    editorSettings.setAdditionalColumnsCount(3);
    editorSettings.setAdditionalLinesCount(3);
    editorSettings.setLineNumbersShown(true);
    editorSettings.setCaretRowShown(true);

    editor.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent e) {
        }
    });
    ((EditorEx) editor).setHighlighter(createHighlighter(FileTypes.PLAIN_TEXT));
    return editor;
}
项目:intellij-ce-playground    文件:RangeMarkerImpl.java   
@Nullable
private static ProperTextRange processIfOnePoint(@NotNull DocumentEvent e, int intervalStart, int intervalEnd, boolean greedyRight) {
  int offset = e.getOffset();
  int oldLength = e.getOldLength();
  int oldEnd = offset + oldLength;
  if (offset < intervalStart && intervalStart < oldEnd) {
    return null;
  }

  if (offset == intervalStart && oldLength == 0 && greedyRight) {
    return new ProperTextRange(intervalStart, intervalEnd + e.getNewLength());
  }

  if (intervalStart > oldEnd || intervalStart == oldEnd  && oldLength > 0) {
    return new ProperTextRange(intervalStart + e.getNewLength() - oldLength, intervalEnd + e.getNewLength() - oldLength);
  }

  return new ProperTextRange(intervalStart, intervalEnd);
}
项目:DarkyenusTimeTracker    文件:TimeTrackerWidget.java   
private void setupAutoStartDocumentListener(boolean enabled) {
    final EditorEventMulticaster editorEventMulticaster = EditorFactory.getInstance().getEventMulticaster();
    if (autoStartDocumentListener != null) {
        editorEventMulticaster.removeDocumentListener(autoStartDocumentListener);
        autoStartDocumentListener = null;
    }
    if (enabled) {
        editorEventMulticaster.addDocumentListener(autoStartDocumentListener = new DocumentListener() {
            @Override
            public void documentChanged(DocumentEvent e) {
                if (running) return;
                //getSelectedTextEditor() must be run from event dispatch thread
                EventQueue.invokeLater(() -> {
                    final Editor selectedTextEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
                    if (selectedTextEditor == null) return;
                    if(e.getDocument().equals(selectedTextEditor.getDocument())) {
                        setRunning(true);
                    }
                });
            }
        });
    }
}
项目:intellij-ce-playground    文件:PackageChooserDialog.java   
private void setupPathComponent(final JPanel northPanel) {
  northPanel.add(new TextFieldAction() {
    @Override
    public void linkSelected(LinkLabel aSource, Object aLinkData) {
      toggleShowPathComponent(northPanel, this);
    }
  }, BorderLayout.EAST);
  myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA);
  myPathEditor.addDocumentListener(new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent e) {
      myAlarm.cancelAllRequests();
      myAlarm.addRequest(new Runnable() {
        @Override
        public void run() {
          updateTreeFromPath();
        }
      }, 300);
    }
  });
  myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
  northPanel.add(myPathEditor, BorderLayout.SOUTH);
}
项目:intellij-ce-playground    文件:SearchSupport.java   
public SearchSupport(EditorTextField textField) {

    myTextField = textField;
    myTextField.getDocument().addDocumentListener(new DocumentAdapter() {
      @Override
      public void documentChanged(DocumentEvent event) {
        onTextChanged();
      }
    });

    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        myTextField.addKeyListener(new KeyAdapter() {
          public void keyPressed(final KeyEvent e) {
              processListSelection(e);
          }
        });
      }
    });

    myList.setVisibleRowCount(10);
    myListModel = new SortedListModel<T>(null);
    myList.setModel(myListModel);
  }
项目:intellij-ce-playground    文件:PersistentRangeHighlighterImpl.java   
@Override
protected void changedUpdateImpl(@NotNull DocumentEvent e) {
  // todo Denis Zhdanov
  DocumentEventImpl event = (DocumentEventImpl)e;
  final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this);
  boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
  if (shouldTranslateViaDiff) {
    wasTranslatedViaDiff = translatedViaDiff(e, event);
  }
  if (!wasTranslatedViaDiff) {
    super.changedUpdateImpl(e);
    if (isValid()) {
      myLine = getDocument().getLineNumber(getStartOffset());
      int endLine = getDocument().getLineNumber(getEndOffset());
      if (endLine != myLine) {
        setIntervalEnd(getDocument().getLineEndOffset(myLine));
      }
    }
  }
  if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
    setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
    setIntervalEnd(getDocument().getLineEndOffset(myLine));
  }
}
项目:intellij-ce-playground    文件:ExternalSystemAutoImporter.java   
@Override
public void documentChanged(DocumentEvent event) {
  Document document = event.getDocument();
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  VirtualFile file = fileDocumentManager.getFile(document);
  if (file == null) {
    return;
  }

  String path = ExternalSystemApiUtil.getLocalFileSystemPath(file);
  for (MyEntry entry : myAutoImportAware) {
    if (entry.aware.getAffectedExternalProjectPath(path, myProject) != null) {
      // Document save triggers VFS event but FileDocumentManager might be registered after the current listener, that's why
      // call to 'saveDocument()' might not produce the desired effect. That's why we reschedule document save if necessary.
      scheduleDocumentSave(document);
      return;
    }
  } 
}
项目:intellij-ce-playground    文件:PersistentRangeMarker.java   
@Nullable
static Pair<ProperTextRange, LinesCols> applyChange(DocumentEvent event, Segment range, int intervalStart, int intervalEnd, boolean greedyLeft, boolean greedyRight, LinesCols linesCols) {
  final boolean shouldTranslateViaDiff = PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, range);
  Pair<ProperTextRange, LinesCols> translated = null;
  if (shouldTranslateViaDiff) {
    translated = translateViaDiff((DocumentEventImpl)event, linesCols);
  }
  if (translated == null) {
    ProperTextRange fallback = applyChange(event, intervalStart, intervalEnd, greedyLeft, greedyRight);
    if (fallback == null) return null;

    LinesCols lc = storeLinesAndCols(fallback, event.getDocument());
    if (lc == null) return null;

    translated = Pair.create(fallback, lc);
  }
  if (translated.first.getEndOffset() > event.getDocument().getTextLength() ||
      translated.second.myEndLine < translated.second.myStartLine ||
      translated.second.myStartLine == translated.second.myEndLine && translated.second.myEndColumn < translated.second.myStartColumn ||
      event.getDocument().getLineCount() < translated.second.myEndLine) {
    return null;
  }

  return translated;
}
项目:intellij-ce-playground    文件:PsiDocumentManagerImpl.java   
@Override
public void documentChanged(DocumentEvent event) {
  super.documentChanged(event);
  // optimisation: avoid documents piling up during batch processing
  if (FileDocumentManagerImpl.areTooManyDocumentsInTheQueue(myUncommittedDocuments)) {
    if (myUnitTestMode) {
      myStopTrackingDocuments = true;
      try {
        LOG.error("Too many uncommitted documents for " + myProject + ":\n" + StringUtil.join(myUncommittedDocuments, "\n") + 
                  "\n\n Project creation trace: " + myProject.getUserData(ProjectImpl.CREATION_TRACE));
      }
      finally {
        //noinspection TestOnlyProblems
        clearUncommittedDocuments();
      }
    }
    // must not commit during document save
    if (PomModelImpl.isAllowPsiModification()) {
      commitAllDocuments();
    }
  }
}
项目:intellij-ce-playground    文件:CompletionAssertions.java   
private void watchTail(int offset) {
  stopWatching();
  tailWatcher = (RangeMarkerEx)getDocument().createRangeMarker(offset, offset);
  if (!tailWatcher.isValid()) {
    throw new AssertionError(getDocument() + "; offset=" + offset);
  }
  tailWatcher.setGreedyToRight(true);
  spy = new RangeMarkerSpy(tailWatcher) {
    @Override
    protected void invalidated(DocumentEvent e) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        LOG.error("Tail offset invalidated, say thanks to the "+ e);
      }

      if (invalidateTrace == null) {
        invalidateTrace = DebugUtil.currentStackTrace();
        killer = e;
      }
    }
  };
  getDocument().addDocumentListener(spy);
}
项目:intellij-ce-playground    文件:LineStatusTracker.java   
@NotNull
private int[] fixRanges(@NotNull DocumentEvent e, int line1, int line2) {
  CharSequence document = myDocument.getCharsSequence();
  int offset = e.getOffset();

  if (e.getOldLength() == 0 && e.getNewLength() != 0) {
    if (StringUtil.endsWithChar(e.getNewFragment(), '\n') && isNewline(offset - 1, document)) {
      return new int[]{line1, line2 - 1};
    }
    if (StringUtil.startsWithChar(e.getNewFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
      return new int[]{line1 + 1, line2};
    }
  }
  if (e.getOldLength() != 0 && e.getNewLength() == 0) {
    if (StringUtil.endsWithChar(e.getOldFragment(), '\n') && isNewline(offset - 1, document)) {
      return new int[]{line1, line2 - 1};
    }
    if (StringUtil.startsWithChar(e.getOldFragment(), '\n') && isNewline(offset + e.getNewLength(), document)) {
      return new int[]{line1 + 1, line2};
    }
  }

  return new int[]{line1, line2};
}
项目:intellij-ce-playground    文件:DocumentChangesCollector.java   
private void mergeChangesIfNecessary(DocumentEvent event) {
  // There is a possible case that we had more than one scattered change (e.g. (3; 5) and (8; 10)) and current document change affects
  // both of them (e.g. remove all symbols from offset (4; 9)). We have two changes then: (3; 4) and (4; 5) and want to merge them
  // into a single one.
  if (myChanges.size() < 2) {
    return;
  }
  TextChangeImpl next = myChanges.get(myChanges.size() - 1);
  for (int i = myChanges.size() - 2; i >= 0; i--) {
    TextChangeImpl current = myChanges.get(i);
    if (current.getEnd() < event.getOffset()) {
      // Assuming that change ranges are always kept at normalized form.
      break;
    }
    if (current.getEnd() == next.getStart()) {
      myChanges.set(i, next = new TextChangeImpl(current.getText().toString() + next.getText(), current.getStart(), next.getEnd()));
      myChanges.remove(i + 1);
    }
    else {
      next = current;
    }
  }
}
项目:intellij-ce-playground    文件:FileAndDocumentListenersForShortDiff.java   
@Override
public void documentChanged(DocumentEvent event) {
  final VirtualFile vf = myFileDocumentManager.getFile(event.getDocument());
  if (vf != null) {
    final FilePath filePath = myDiffDetails.getCurrentFilePath();
    if (filePath != null && filePath.getVirtualFile() != null && filePath.getVirtualFile().equals(vf)) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          if (! updateSynchronously()) {
            impl(vf);
          }
        }
      });
    } else {
      impl(vf);
    }
  }
}
项目:intellij-ce-playground    文件:DocumentChangesCollector.java   
@Override
public void documentChanged(DocumentEvent event) {
  if (!myCollectChanges) {
    return;
  }

  // The general algorithm is as follows:
  //   1. Drop or cut stored change ranges for removed range if any;
  //   2. Update offsets of all ranges that lays after the last change range identified by the given document change event;
  //   3. Merge added range with registered changes if any;
  //   4. Merge all adjacent ranges if any;
  StringBuilder oldText = new StringBuilder(event.getOldFragment());

  cutChangesIfNecessary(event, oldText);
  updateChanges(event, oldText);
  mergeChangesIfNecessary(event);
}
项目:intellij-ce-playground    文件:PythonEditorHighlighter.java   
@Override
public void documentChanged(DocumentEvent e) {
  synchronized (this) {
    final Document document = e.getDocument();
    Lexer l = getLexer();
    // if the document been changed before "from __future__ import unicode_literals"
    // we should update the whole document
    if (l instanceof LayeredLexer) {
      Lexer delegate = ((LayeredLexer)l).getDelegate();
      int offset = e.getOffset();
      int lineNumber = document.getLineNumber(offset);
      TextRange tr = new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber));
      document.putUserData(KEY, document.getText(tr).indexOf(PyNames.UNICODE_LITERALS) == -1);
      Boolean hasUnicodeImport = document.getUserData(KEY);
      if (delegate instanceof PythonHighlightingLexer &&
          (((PythonHighlightingLexer)delegate).getImportOffset() > e.getOffset()
           || hasUnicodeImport != hadUnicodeImport)) {
        ((PythonHighlightingLexer)delegate).clearState(e.getDocument().getTextLength());
        setText(document.getCharsSequence());
      }
      else super.documentChanged(e);
    }
    else super.documentChanged(e);
  }
}
项目:Gherkin-TS-Runner    文件:GherkinDocumentListener.java   
@Override
public void documentChanged(DocumentEvent documentEvent) {
    try {
        // System.out.println("[Document Changed] " + fileName);
        // Remove old run icons before add new ones
        gherkinIconUtils.removeGherkinRunIcons(editor);
        // Generate new run icons
        gherkinIconUtils.generateGherkinRunIcons(documentEvent.getDocument(), editor);
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}
项目:educational-plugin    文件:EduDocumentListener.java   
@Override
public void beforeDocumentChange(DocumentEvent e) {
  if (!myTaskFile.isTrackChanges()) {
    return;
  }
  myTaskFile.setHighlightErrors(true);
  myAnswerPlaceholders.clear();
  for (AnswerPlaceholder answerPlaceholder : myTaskFile.getAnswerPlaceholders()) {
    int twStart = answerPlaceholder.getOffset();
    int length = answerPlaceholder.getRealLength();
    int twEnd = twStart + length;
    myAnswerPlaceholders.add(new AnswerPlaceholderWrapper(answerPlaceholder, twStart, twEnd));
  }
}
项目:educational-plugin    文件:EduDocumentListener.java   
@Override
public void documentChanged(DocumentEvent e) {
  if (!myTaskFile.isTrackChanges()) {
    return;
  }
  if (myAnswerPlaceholders.isEmpty()) return;
  if (e instanceof DocumentEventImpl) {
    DocumentEventImpl event = (DocumentEventImpl)e;
    Document document = e.getDocument();
    int offset = e.getOffset();
    int change = event.getNewLength() - event.getOldLength();
    for (AnswerPlaceholderWrapper answerPlaceholderWrapper : myAnswerPlaceholders) {
      int twStart = answerPlaceholderWrapper.getTwStart();
      if (twStart > offset) {
        twStart += change;
      }
      int twEnd = answerPlaceholderWrapper.getTwEnd();
      if (twEnd >= offset) {
        twEnd += change;
      }
      AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
      int length = twEnd - twStart;
      answerPlaceholder.setOffset(twStart);
      if (myTrackLength) {
        if (answerPlaceholder.getUseLength()) {
          answerPlaceholder.setLength(length);
        } else {
          if (answerPlaceholder.isActive() && myTaskFile.isTrackLengths()) {
            answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
          }
        }
      }
    }
  }
}
项目:appetizer-intellij    文件:DocumentChangeListener.java   
public void documentChanged(DocumentEvent event) {
  Editor[] editors = EditorFactory.getInstance().getEditors(event.getDocument());
  for (Editor editor : editors) {
    editor.getMarkupModel().removeAllHighlighters();
    HighLight.removeAll();
  }
}
项目:tmc-intellij    文件:TextInputListener.java   
@Override
public void documentChanged(DocumentEvent documentEvent) {
    modified = documentEvent.getDocument().getText();
    if (!isThisCorrectProject() || changeIsNotJustWhitespace(documentEvent)) {
        logger.info(
                "not creating path for event, as project wasn't "
                        + "correct one or change was just white space");
        return;
    }

    logger.info("Creating patches for ", documentEvent.getSource());
    createPatches(
            PathResolver.getExercise(new ObjectFinder().findCurrentProject().getBasePath()),
            documentEvent);
}
项目:intellij-ce-playground    文件:OffsetTranslator.java   
@Nullable
public Integer translateOffset(Integer offset) {
  for (DocumentEvent event : myTranslation) {
    offset = translateOffset(offset, event);
    if (offset == null) {
      return null;
    }
  }
  return offset;
}
项目:tmc-intellij    文件:TextInputListener.java   
private boolean isPasteEvent(DocumentEvent documentEvent) {
    if (ClipboardService.getClipBoard() == null) {
        return false;
    }
    return (documentEvent.getNewLength() > 2)
            && ClipboardService.getClipBoard()
                    .trim()
                    .equals(documentEvent.getNewFragment().toString().trim());
}
项目:intellij-ce-playground    文件:DocumentImpl.java   
private void updateText(@NotNull ImmutableText newText,
                        int offset,
                        @Nullable CharSequence oldString,
                        @Nullable CharSequence newString,
                        boolean wholeTextReplaced,
                        long newModificationStamp,
                        int initialStartOffset,
                        int initialOldLength) {
  assertNotNestedModification();
  boolean enableRecursiveModifications = Registry.is("enable.recursive.document.changes"); // temporary property, to remove in IDEA 16
  myChangeInProgress = true;
  try {
    DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced, initialStartOffset, initialOldLength);
    try {
      doBeforeChangedUpdate(event);
    }
    finally {
      if (enableRecursiveModifications) {
        myChangeInProgress = false;
      }
    }
    myTextString = null;
    ImmutableText prevText = myText;
    myText = newText;
    changedUpdate(event, newModificationStamp, prevText);
  }
  finally {
    if (!enableRecursiveModifications) {
      myChangeInProgress = false;
    }
  }
}
项目:intellij-ce-playground    文件:DebuggerExpressionComboBox.java   
@Override
public void documentChanged(DocumentEvent e) {
  final String text = e.getNewFragment().toString();
  final String replaced = text.replace('\n', ' ');
  if (replaced != text) {
    e.getDocument().replaceString(e.getOffset(), e.getOffset() + e.getNewLength(), replaced);
  }
}
项目:intellij-ce-playground    文件:MoveMembersDialog.java   
protected JComponent createNorthPanel() {
  JPanel panel = new JPanel(new BorderLayout());

  JPanel _panel;
  Box box = Box.createVerticalBox();

  _panel = new JPanel(new BorderLayout());
  JTextField sourceClassField = new JTextField();
  sourceClassField.setText(mySourceClassName);
  sourceClassField.setEditable(false);
  _panel.add(new JLabel(RefactoringBundle.message("move.members.move.members.from.label")), BorderLayout.NORTH);
  _panel.add(sourceClassField, BorderLayout.CENTER);
  box.add(_panel);

  box.add(Box.createVerticalStrut(10));

  _panel = new JPanel(new BorderLayout());
  JLabel label = new JLabel(RefactoringBundle.message("move.members.to.fully.qualified.name.label"));
  label.setLabelFor(myTfTargetClassName);
  _panel.add(label, BorderLayout.NORTH);
  _panel.add(myTfTargetClassName, BorderLayout.CENTER);
  _panel.add(myIntroduceEnumConstants, BorderLayout.SOUTH);
  box.add(_panel);

  myTfTargetClassName.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {
    public void documentChanged(DocumentEvent e) {
      myMemberInfoModel.updateTargetClass();
      validateButtons();
    }
  });

  panel.add(box, BorderLayout.CENTER);
  panel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);

  validateButtons();
  return panel;
}
项目:intellij-ce-playground    文件:EditVarConstraintsDialog.java   
@Override
public void documentChanged(DocumentEvent e) {
  final boolean enable = e.getDocument().getTextLength() > 0;
  for (JComponent component : components) {
    component.setEnabled(enable);
  }
}
项目:intellij-ce-playground    文件:MoveClassesOrPackagesDialog.java   
private ReferenceEditorComboWithBrowseButton createPackageChooser() {
  final ReferenceEditorComboWithBrowseButton packageChooser =
    new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
  final Document document = packageChooser.getChildComponent().getDocument();
  document.addDocumentListener(new DocumentAdapter() {
    public void documentChanged(DocumentEvent e) {
      validateButtons();
    }
  });

  return packageChooser;
}
项目:intellij-ce-playground    文件:ChangeSignatureDialogBase.java   
@Override
protected final JBTableRowEditor getRowEditor(final int row) {
  JBTableRowEditor editor = getRowEditor(getRowItem(row));
  editor.addDocumentListener(new JBTableRowEditor.RowDocumentListener() {
    @Override
    public void documentChanged(DocumentEvent e, int column) {
      if (String.class.equals(myParametersTableModel.getColumnClass(column))) {
        myParametersTableModel.setValueAtWithoutUpdate(e.getDocument().getText(), row, column);
      }
      updateSignature();
    }
  });
  return editor;
}
项目:intellij-ce-playground    文件:DocumentFragmentContent.java   
@Override
protected void onDocumentChanged1(@NotNull DocumentEvent event) {
  if (!myRangeMarker.isValid()) {
    myDocument2.setReadOnly(false);
    replaceString(myDocument2, 0, myDocument2.getTextLength(), "Invalid selection range");
    myDocument2.setReadOnly(true);
    return;
  }
  CharSequence newText = myDocument1.getCharsSequence().subSequence(myRangeMarker.getStartOffset(), myRangeMarker.getEndOffset());
  replaceString(myDocument2, 0, myDocument2.getTextLength(), newText);
}
项目:intellij-ce-playground    文件:GrInplaceParameterIntroducer.java   
@Override
protected JComponent getComponent() {

  JPanel previewPanel = new JPanel(new BorderLayout());
  previewPanel.add(getPreviewEditor().getComponent(), BorderLayout.CENTER);
  previewPanel.setBorder(new EmptyBorder(2, 2, 6, 2));

  DocumentAdapter documentAdapter = new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent e) {
      final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
      if (templateState != null) {
        final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME);
        if (value != null) {
          updateTitle(getVariable(), value.getText());
        }
      }
    }
  };
  myEditor.getDocument().addDocumentListener(documentAdapter);

  myDelegateCB = new JBCheckBox("Delegate via overloading method");
  myDelegateCB.setMnemonic('l');
  myDelegateCB.setFocusable(false);

  JPanel panel = new JPanel(new BorderLayout());
  panel.add(previewPanel, BorderLayout.CENTER);
  panel.add(myDelegateCB, BorderLayout.SOUTH);
  return panel;
}
项目:intellij-ce-playground    文件:UnifiedDiffViewer.java   
@Override
protected void onDocumentChange(@NotNull DocumentEvent e) {
  if (myDuringTwosideDocumentModification) return;

  markStateIsOutOfDate();
  markSuppressEditorTyping();

  myFoldingModel.onDocumentChanged(e);
  scheduleRediff();
}
项目:intellij-ce-playground    文件:MarkerCache.java   
synchronized void updateMarkers(@NotNull FrozenDocument frozen, @NotNull List<DocumentEvent> events) {
  TLongObjectHashMap<ManualRangeMarker> updated = getUpdatedMarkers(frozen, events);

  for (SelfElementInfo info : getInfos()) {
    long key = info.markerCacheKey();
    if (key != 0) {
      ManualRangeMarker newRangeMarker = updated.get(key);
      info.setRange(newRangeMarker == null ? null : newRangeMarker.getRange());
    }
  }

  myUpdatedRanges = null;
}
项目:intellij-ce-playground    文件:SimpleDiffViewer.java   
@Override
@CalledInAwt
protected void onBeforeDocumentChange(@NotNull DocumentEvent e) {
  super.onBeforeDocumentChange(e);
  if (myDiffChanges.isEmpty()) return;

  Side side = null;
  if (e.getDocument() == getEditor(Side.LEFT).getDocument()) side = Side.LEFT;
  if (e.getDocument() == getEditor(Side.RIGHT).getDocument()) side = Side.RIGHT;
  if (side == null) {
    LOG.warn("Unknown document changed");
    return;
  }

  int line1 = e.getDocument().getLineNumber(e.getOffset());
  int line2 = e.getDocument().getLineNumber(e.getOffset() + e.getOldLength()) + 1;
  int shift = DiffUtil.countLinesShift(e);

  List<SimpleDiffChange> invalid = new ArrayList<SimpleDiffChange>();
  for (SimpleDiffChange change : myDiffChanges) {
    if (change.processChange(line1, line2, shift, side)) {
      invalid.add(change);
    }
  }

  if (!invalid.isEmpty()) {
    myDiffChanges.removeAll(invalid);
    myInvalidDiffChanges.addAll(invalid);
  }
}
项目:intellij-ce-playground    文件:SimpleThreesideDiffViewer.java   
@Override
@CalledInAwt
protected void onBeforeDocumentChange(@NotNull DocumentEvent e) {
  super.onBeforeDocumentChange(e);
  if (myDiffChanges.isEmpty()) return;

  ThreeSide side = null;
  if (e.getDocument() == getEditor(ThreeSide.LEFT).getDocument()) side = ThreeSide.LEFT;
  if (e.getDocument() == getEditor(ThreeSide.RIGHT).getDocument()) side = ThreeSide.RIGHT;
  if (e.getDocument() == getEditor(ThreeSide.BASE).getDocument()) side = ThreeSide.BASE;
  if (side == null) {
    LOG.warn("Unknown document changed");
    return;
  }

  int line1 = e.getDocument().getLineNumber(e.getOffset());
  int line2 = e.getDocument().getLineNumber(e.getOffset() + e.getOldLength()) + 1;
  int shift = DiffUtil.countLinesShift(e);

  List<SimpleThreesideDiffChange> invalid = new ArrayList<SimpleThreesideDiffChange>();
  for (SimpleThreesideDiffChange change : myDiffChanges) {
    if (change.processChange(line1, line2, shift, side)) {
      invalid.add(change);
    }
  }

  if (!invalid.isEmpty()) {
    myDiffChanges.removeAll(invalid);
    myInvalidDiffChanges.addAll(invalid);
  }
}
项目:intellij-ce-playground    文件:MarkerCache.java   
private TLongObjectHashMap<ManualRangeMarker> getUpdatedMarkers(@NotNull FrozenDocument frozen, @NotNull List<DocumentEvent> events) {
  int eventCount = events.size();
  assert eventCount > 0;

  Trinity<Integer, TLongObjectHashMap<ManualRangeMarker>, FrozenDocument> cache = myUpdatedRanges;
  if (cache != null && cache.first.intValue() == eventCount) return cache.second;

  //noinspection SynchronizeOnThis
  synchronized (this) {
    cache = myUpdatedRanges;
    if (cache != null && cache.first.intValue() == eventCount) return cache.second;

    TLongObjectHashMap<ManualRangeMarker> answer;
    if (cache != null && cache.first < eventCount) {
      // apply only the new events
      answer = cache.second.clone();
      frozen = applyEvents(cache.third, events.subList(cache.first, eventCount), answer);
    }
    else {
      List<SelfElementInfo> infos = getInfos();
      answer = new TLongObjectHashMap<ManualRangeMarker>(infos.size());
      for (SelfElementInfo info : infos) {
        ProperTextRange range = info.getPsiRange();
        long key = info.markerCacheKey();
        if (range != null && key != 0) {
          boolean forInjected = info.isForInjected();
          answer.put(key, new ManualRangeMarker(frozen, range, forInjected, forInjected, !forInjected));
        }
      }
      frozen = applyEvents(frozen, events, answer);
    }

    myUpdatedRanges = Trinity.create(eventCount, answer, frozen);
    return answer;
  }
}
项目:intellij-ce-playground    文件:FoldingModelSupport.java   
public void onDocumentChanged(@NotNull DocumentEvent e) {
  if (StringUtil.indexOf(e.getOldFragment(), '\n') != -1 ||
      StringUtil.indexOf(e.getNewFragment(), '\n') != -1) {
    for (int i = 0; i < myCount; i++) {
      if (myEditors[i].getDocument() == e.getDocument()) {
        myShouldUpdateLineNumbers[i] = true;
      }
    }
  }
}
项目:intellij-ce-playground    文件:HgPushTargetPanel.java   
@Override
public void addTargetEditorListener(@NotNull final PushTargetEditorListener listener) {
  myDestTargetPanel.addDocumentListener(new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent e) {
      super.documentChanged(e);
      listener.onTargetInEditModeChanged(myDestTargetPanel.getText());
    }
  });
}
项目:intellij-ce-playground    文件:PsiDocumentManagerBase.java   
@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
  if (myStopTrackingDocuments || myProject.isDisposed()) return;

  final Document document = event.getDocument();
  VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
  boolean isRelevant = virtualFile != null && isRelevant(virtualFile);

  if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
    myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl)document));
  }

  final FileViewProvider viewProvider = getCachedViewProvider(document);
  boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
  if (!isRelevant || !inMyProject) {
    return;
  }

  final List<PsiFile> files = viewProvider.getAllFiles();
  PsiFile psiCause = null;
  for (PsiFile file : files) {
    if (file == null) {
      throw new AssertionError("View provider "+viewProvider+" ("+viewProvider.getClass()+") returned null in its files array: "+files+" for file "+viewProvider.getVirtualFile());
    }

    if (mySynchronizer.isInsideAtomicChange(file)) {
      psiCause = file;
    }
  }

  if (psiCause == null) {
    beforeDocumentChangeOnUnlockedDocument(viewProvider);
  }

  ((SingleRootFileViewProvider)viewProvider).beforeDocumentChanged(psiCause);
}