@Override public void caretPositionChanged(CaretEvent event) { if (project.isDisposed()) { return; } VirtualFile file = FileDocumentManager.getInstance().getFile(event.getEditor().getDocument()); // Make sure file exists if (file == null) { return; } // Make sure file is in the project if (!ProjectFileIndex.SERVICE.getInstance(project).isInSource(file)) { return; } int offset = event.getEditor().logicalPositionToOffset(event.getNewPosition()); // Get path relative to project root (e.g. src/Sample.java) Path basePath = Paths.get(project.getBasePath()); Path absoluteFilePath = Paths.get(file.getPath()); String relativeFilePath = basePath.relativize(absoluteFilePath).toString(); CursorMovement cursorMovement = new CursorMovement(-1, relativeFilePath, offset); for (EditorEvent editorEvent : events) { editorEvent.sendCursorMovement(cursorMovement); } }
public void editingCanceled(CaretEvent e) { if (e.getCaret() != caret) { e.getCaret().removeCaretListener(this); return; } caret.removeCaretListener(this); caretCircuit.removeCircuitListener(this); caretCircuit = null; caretComponent = null; caretCreatingText = false; caret = null; }
public void caretUpdate(CaretEvent e) { // when the cursor moves on _textView // this method will be called. Then, we // must determine what the line number is // and update the line number view Element root = textView.getDocument().getDefaultRootElement(); int line = root.getElementIndex(e.getDot()); root = root.getElement(line); int col = root.getElementIndex(e.getDot()); lineNumberView.setText(line + ":" + col); // if text is selected then enable copy and cut boolean isSelection = e.getDot() != e.getMark(); copyAction.setEnabled(isSelection); cutAction.setEnabled(isSelection); }
public void caretUpdate(CaretEvent e) { int dot = e.getDot(); int mark = e.getMark(); if (dot == mark) { // no selection if (caretValue != dot) { caretValue = dot; } if (debug && caretCmd != null) System.out.println("caret @: " + caretValue); if (hasFocus()) { // Update widget and vnmr variables every time something // happens in the widget sendTextCmd(); sendCaretCmd(); } return; } }
public void editingStopped(CaretEvent e) { if (e.getCaret() != caret) { e.getCaret().removeCaretListener(this); return; } caret.removeCaretListener(this); caretCircuit.removeCircuitListener(this); String val = caret.getText(); boolean isEmpty = (val == null || val.equals("")); Action a; Project proj = caretCanvas.getProject(); if (caretCreatingText) { if (!isEmpty) { CircuitMutation xn = new CircuitMutation(caretCircuit); xn.add(caretComponent); a = xn.toAction(Strings.getter("addComponentAction", Text.FACTORY.getDisplayGetter())); } else { a = null; // don't add the blank text field } } else { if (isEmpty && caretComponent.getFactory() instanceof Text) { CircuitMutation xn = new CircuitMutation(caretCircuit); xn.add(caretComponent); a = xn.toAction(Strings.getter("removeComponentAction", Text.FACTORY.getDisplayGetter())); } else { Object obj = caretComponent.getFeature(TextEditable.class); if (obj == null) { // should never happen a = null; } else { TextEditable editable = (TextEditable) obj; a = editable.getCommitAction(caretCircuit, e.getOldText(), e.getText()); } } } caretCircuit = null; caretComponent = null; caretCreatingText = false; caret = null; if (a != null) proj.doAction(a); }
@Override public void caretUpdate(CaretEvent event) { doCaretUpdate(event.getDot(), event.getMark()); }