Skip to content

Export visibleLines to public api#1556

Closed
aslushnikov wants to merge 1 commit intocodemirror:masterfrom
aslushnikov:visible-lines
Closed

Export visibleLines to public api#1556
aslushnikov wants to merge 1 commit intocodemirror:masterfrom
aslushnikov:visible-lines

Conversation

@aslushnikov
Copy link
Copy Markdown
Contributor

Problem

The only way to figure out a first visible line number (or a bottom visible line number)
is to call codeMirror.coordsChar({left: 0, top: 0}, "local"). (please correct me if I'm wrong).
The problem is, however, that this method is pretty expensive because of a measureLineInner call, so in case of calling it multiple times in a scroll event handler on a file with multiple long lines - scrolling gets laggy.

The visibleLines method seems to be a natural solution for the problem.

marijnh added a commit that referenced this pull request May 30, 2013
@marijnh
Copy link
Copy Markdown
Member

marijnh commented May 30, 2013

Please see my attached patch instead -- I guess a general way to cheaply find the line at a given y offset would be more generally useful, and less 'random exposed internals'-y.

@marijnh marijnh closed this May 30, 2013
@aslushnikov
Copy link
Copy Markdown
Contributor Author

Does the editor.lineAtHeight(0, "local") return the top visible line? It always returns 0 for me

@marijnh
Copy link
Copy Markdown
Member

marijnh commented May 30, 2013

No, it returns the first line -- i.e. the line at offset 0. "local" coordinates are not scroll-sensitive.

editor.lineAtHeight(editor.getScrollInfo().top, "local") will probably work better.

@aslushnikov aslushnikov deleted the visible-lines branch May 30, 2013 13:04
@aslushnikov
Copy link
Copy Markdown
Contributor Author

Thanks, that works.

anaran pushed a commit to anaran/CodeMirror that referenced this pull request Feb 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants