private boolean isSetupChunk(Element el, AceEditorNative editor) {
    int pageX = el.getAbsoluteLeft();
    int pageY = el.getAbsoluteTop();

    Position position = editor.getRenderer().screenToTextCoordinates(pageX, pageY);

    String line = editor.getSession().getLine(position.getRow());

    return line.contains("r setup");
  }
Exemple #2
0
  private void doSetCode(String code, boolean preserveCursorPosition) {
    // Filter out Escape characters that might have snuck in from an old
    // bug in 0.95. We can choose to remove this when 0.95 ships, hopefully
    // any documents that would be affected by this will be gone by then.
    code = code.replaceAll("\u001B", "");

    final AceEditorNative ed = widget_.getEditor();

    if (preserveCursorPosition) {
      final Position cursorPos;
      final int scrollTop, scrollLeft;

      cursorPos = ed.getSession().getSelection().getCursor();
      scrollTop = ed.getRenderer().getScrollTop();
      scrollLeft = ed.getRenderer().getScrollLeft();

      // Setting the value directly on the document prevents undo/redo
      // stack from being blown away
      widget_.getEditor().getSession().getDocument().setValue(code);

      ed.getSession().getSelection().moveCursorTo(cursorPos.getRow(), cursorPos.getColumn(), false);
      ed.getRenderer().scrollToY(scrollTop);
      ed.getRenderer().scrollToX(scrollLeft);
      Scheduler.get()
          .scheduleDeferred(
              new ScheduledCommand() {
                @Override
                public void execute() {
                  ed.getRenderer().scrollToY(scrollTop);
                  ed.getRenderer().scrollToX(scrollLeft);
                }
              });
    } else {
      ed.getSession().setValue(code);
      ed.getSession().getSelection().moveCursorTo(0, 0, false);
    }
  }
  private Position toDocumentPosition(Element el, AceEditorNative editor) {
    int pageX = el.getAbsoluteLeft();
    int pageY = el.getAbsoluteTop();

    return editor.getRenderer().screenToTextCoordinates(pageX, pageY);
  }