}
Document document = editor.getDocument();
LineFinder lineFinder = document.getLineFinder();
LineInfo baseLineInfo =
lineFinder.findLine(Math.min(selection.baseLineNumber, document.getLastLineNumber()));
int baseColumn = LineUtils.rubberbandColumn(baseLineInfo.line(), selection.baseColumn);
final LineInfo cursorLineInfo =
lineFinder.findLine(Math.min(selection.cursorLineNumber, document.getLastLineNumber()));
int cursorColumn = LineUtils.rubberbandColumn(cursorLineInfo.line(), selection.cursorColumn);
editor.getSelection().setSelection(baseLineInfo, baseColumn, cursorLineInfo, cursorColumn);
// Defer to match editor's initially deferred scrolling
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Buffer buffer = editor.getBuffer();
int targetScrollTop = buffer.calculateLineTop(cursorLineInfo.number())
- selection.cursorScrollTopOffset;
buffer.setScrollTop(Math.max(0, targetScrollTop));
}
});
}