use of org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler in project rstudio by rstudio.
the class ConnectionCodePanel method setCode.
public void setCode(String code, String connectVia) {
settingCode_ = true;
// clear existing code viewer
if (codeViewer_ != null) {
codeViewer_.removeFromParent();
codeViewer_ = null;
}
// create new code viewer
codeViewer_ = new AceEditorWidget(false);
codeViewer_.addStyleName(RES.styles().codeViewer());
codeViewer_.getEditor().getSession().setEditorMode(EditorLanguage.LANG_R.getParserName(), false);
codeViewer_.getEditor().getSession().setUseWrapMode(true);
codeViewer_.getEditor().getRenderer().setShowGutter(false);
codeViewer_.getEditor().setReadOnly(false);
codeViewer_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
EditSession session = codeViewer_.getEditor().getSession();
String selectedCode = session.getTextRange(session.getSelection().getRange());
if (!settingCode_ && selectedCode.trim().equals(session.getValue().trim())) {
setConnectVia(ConnectionOptions.CONNECT_COPY_TO_CLIPBOARD);
}
}
});
codeViewer_.setCode(code);
container_.add(codeViewer_);
// update connectVia
if (connectVia != null) {
setConnectVia(connectVia);
updateConnectViaUI_.execute();
}
onResize();
settingCode_ = false;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler in project rstudio by rstudio.
the class MathJax method beginCursorMonitoring.
private void beginCursorMonitoring() {
endCursorMonitoring();
cursorChangedHandler_ = docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
Position position = event.getPosition();
if (anchor_ == null || !anchor_.getRange().contains(position))
endRender();
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler in project rstudio by rstudio.
the class TextEditingTargetIdleMonitor method beginMonitoring.
public void beginMonitoring() {
endMonitoring();
monitors_.add(display_.addEditorModeChangedHandler(new EditorModeChangedEvent.Handler() {
@Override
public void onEditorModeChanged(EditorModeChangedEvent event) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
refreshCommands();
}
});
}
}));
monitors_.add(display_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
mouseMovedLast_ = false;
timer_.schedule(DELAY_MS);
}
}));
monitors_.add(display_.addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
if (!event.isAttached())
onDetach();
}
}));
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler in project rstudio by rstudio.
the class EditingTargetInlineChunkExecution method execute.
public void execute(Range range) {
// synthesize an identifier for this chunk execution
final String chunkId = "i" + StringUtil.makeRandomId(12);
// are, remove it to make way for the new one
for (ChunkInlineOutput output : outputs_.values()) {
if (output.range().isEqualTo(range)) {
if (output.state() == ChunkInlineOutput.State.Finished) {
// remove old, completed output for this input
output.hide();
outputs_.remove(output.chunkId());
} else {
// unintended duplicate.
return;
}
}
}
// create dummy scope for execution
Scope scope = Scope.createRScopeNode(chunkId, range.getStart(), range.getEnd(), Scope.SCOPE_TYPE_CHUNK);
// create popup panel to host output
final ChunkInlineOutput output = new ChunkInlineOutput(chunkId, display_.createAnchoredSelection(range.getStart(), range.getEnd()));
// auto dismiss the panel when the cursor leaves the inline chunk
final Mutable<HandlerRegistration> cursorHandler = new Mutable<HandlerRegistration>();
cursorHandler.set(display_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
Position position = event.getPosition();
if (!output.range().contains(position)) {
output.hide();
}
}
}));
// when the popup is dismissed, clean up local state
output.addCloseHandler(new CloseHandler<PopupPanel>() {
@Override
public void onClose(CloseEvent<PopupPanel> event) {
outputs_.remove(chunkId);
cursorHandler.get().removeHandler();
}
});
// render offscreen until complete
output.setPopupPosition(-100000, -100000);
output.show();
outputs_.put(chunkId, output);
SendToChunkConsoleEvent event = new SendToChunkConsoleEvent(docId_, scope, range, NotebookQueueUnit.EXEC_SCOPE_INLINE);
events_.fireEvent(event);
}
Aggregations