use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates in project rstudio by rstudio.
the class AceEditor method getRangeBounds.
@Override
public Rectangle getRangeBounds(Range range) {
range = Range.toOrientedRange(range);
Renderer renderer = widget_.getEditor().getRenderer();
if (!range.isMultiLine()) {
ScreenCoordinates start = documentPositionToScreenCoordinates(range.getStart());
ScreenCoordinates end = documentPositionToScreenCoordinates(range.getEnd());
int width = (end.getPageX() - start.getPageX()) + (int) renderer.getCharacterWidth();
int height = (end.getPageY() - start.getPageY()) + (int) renderer.getLineHeight();
return new Rectangle(start.getPageX(), start.getPageY(), width, height);
}
Position startPos = range.getStart();
Position endPos = range.getEnd();
int startRow = startPos.getRow();
int endRow = endPos.getRow();
// figure out top left coordinates
ScreenCoordinates topLeft = documentPositionToScreenCoordinates(Position.create(startRow, 0));
// figure out bottom right coordinates (need to walk rows to figure out longest line)
ScreenCoordinates bottomRight = documentPositionToScreenCoordinates(Position.create(endPos));
for (int row = startRow; row <= endRow; row++) {
Position rowEndPos = Position.create(row, getLength(row));
ScreenCoordinates coords = documentPositionToScreenCoordinates(rowEndPos);
if (coords.getPageX() > bottomRight.getPageX())
bottomRight = ScreenCoordinates.create(coords.getPageX(), bottomRight.getPageY());
}
// construct resulting range
int width = (bottomRight.getPageX() - topLeft.getPageX()) + (int) renderer.getCharacterWidth();
int height = (bottomRight.getPageY() - topLeft.getPageY()) + (int) renderer.getLineHeight();
return new Rectangle(topLeft.getPageX(), topLeft.getPageY(), width, height);
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates in project rstudio by rstudio.
the class ImagePreviewer method onPreviewImage.
private static void onPreviewImage(DocDisplay display, DocUpdateSentinel sentinel, UIPrefs prefs, String href, String attributes, Position position, Range tokenRange) {
// check to see if we already have a popup showing for this image;
// if we do then bail early
String encoded = StringUtil.encodeURIComponent(href);
Element el = Document.get().getElementById(encoded);
if (el != null)
return;
String pref = prefs.showLatexPreviewOnCursorIdle().getValue();
// skip if disabled entirely
if (!sentinel.getBoolProperty(TextEditingTargetNotebook.CONTENT_PREVIEW_ENABLED, pref != UIPrefsAccessor.LATEX_PREVIEW_SHOW_NEVER))
return;
// display stand-alone links as line widgets (if enabled)
String line = display.getLine(position.getRow());
if (isStandaloneMarkdownLink(line) && sentinel.getBoolProperty(TextEditingTargetNotebook.CONTENT_PREVIEW_INLINE, prefs.showLatexPreviewOnCursorIdle().getValue() == UIPrefsAccessor.LATEX_PREVIEW_SHOW_ALWAYS)) {
onPreviewImageLineWidget(display, sentinel, href, attributes, position, tokenRange);
return;
}
// construct image el, place in popup, and show
ImagePreviewPopup panel = new ImagePreviewPopup(display, tokenRange, href, imgSrcPathFromHref(sentinel, href));
panel.getElement().setId(encoded);
ScreenCoordinates coordinates = display.documentPositionToScreenCoordinates(position);
panel.setPopupPosition(coordinates.getPageX(), coordinates.getPageY() + 20);
panel.show();
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates in project rstudio by rstudio.
the class AceEditor method getPositionBounds.
@Override
public Rectangle getPositionBounds(Position position) {
Renderer renderer = widget_.getEditor().getRenderer();
ScreenCoordinates start = renderer.textToScreenCoordinates(position.getRow(), position.getColumn());
return new Rectangle(start.getPageX(), start.getPageY(), (int) Math.round(renderer.getCharacterWidth()), (int) (renderer.getLineHeight() * 0.8));
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates in project rstudio by rstudio.
the class AceEditor method toScreenCoordinates.
public Rectangle toScreenCoordinates(Range range) {
Renderer renderer = widget_.getEditor().getRenderer();
ScreenCoordinates start = renderer.textToScreenCoordinates(range.getStart().getRow(), range.getStart().getColumn());
ScreenCoordinates end = renderer.textToScreenCoordinates(range.getEnd().getRow(), range.getEnd().getColumn());
return new Rectangle(start.getPageX(), start.getPageY(), end.getPageX() - start.getPageX(), renderer.getLineHeight());
}
Aggregations