Skip to content

Commit

Permalink
Merge pull request #363 from eclipse/CHE-95
Browse files Browse the repository at this point in the history
CHE-95. Fix wrong scrolling in editor at using code assistant
  • Loading branch information
RomanNikitenko committed Feb 17, 2016
2 parents 20dc116 + 8cb6e27 commit c77e5ac
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.google.web.bindery.event.shared.HandlerRegistration;

import org.eclipse.che.ide.api.text.Region;
import org.eclipse.che.ide.editor.orion.client.jso.ModelChangedEventOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionPixelPositionOverlay;
Expand All @@ -36,6 +35,9 @@
*/
public class OrionDocument extends AbstractEmbeddedDocument {

/** The maximum number of lines that may be visible at the top of the text view after setting selection range. */
private final static int MARGIN_TOP = 15;

private final OrionTextViewOverlay textViewOverlay;
private final OrionPositionConverter positionConverter;
private final HasCursorActivityHandlers hasCursorActivityHandlers;
Expand Down Expand Up @@ -243,5 +245,12 @@ public LinearRange getSelectedLinearRange() {
public void setSelectedRange(LinearRange range, boolean show) {
int startOffset = range.getStartOffset();
editorOverlay.setSelection(startOffset, startOffset + range.getLength(), show);

TextPosition position = getPositionFromIndex(startOffset);
if (show && position != null) {
int lineNumber = position.getLine();
int topIndex = lineNumber - MARGIN_TOP;
editorOverlay.getTextView().setTopIndex(topIndex > 0 ? topIndex : 0);
}
}
}

0 comments on commit c77e5ac

Please sign in to comment.