Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve scroll position in markdown viewer #830

Closed
lijunle opened this issue Mar 31, 2014 · 11 comments · Fixed by #832
Closed

Preserve scroll position in markdown viewer #830

lijunle opened this issue Mar 31, 2014 · 11 comments · Fixed by #832

Comments

@lijunle
Copy link

lijunle commented Mar 31, 2014

Hi, I am getting into trouble. After save a markdown file, the content is rendered automatically, and the scroll bar of the preview pane always go back to the top.

I get a FIXED from this link, but I still got the trouble in the latest stable version (v1.9).

Besides, I cannot try nightly build (v1.9.8) because I do not have VS 2013 Update 2.

@am11
Copy link
Contributor

am11 commented Mar 31, 2014

You are right. This is happening with nightly build too.

@lijunle
Copy link
Author

lijunle commented Mar 31, 2014

Is it consider as a bug, or a feature?

Besides, could you make the edit pane and preview pane scroll synchronously?

@am11
Copy link
Contributor

am11 commented Mar 31, 2014

Is it consider as a bug, or a feature?

I guess that is a bug.

Besides, could you make the edit pane and preview pane scroll synchronously?

That would require source-to-source mapping to keep the track of corresponding snapshot. Otherwise, changes in rendered font-size may lead to the scenarios where it would lose the scope. This might give you some idea about the nature of this problem: #783.

@lijunle
Copy link
Author

lijunle commented Mar 31, 2014

So, is there a .map file for markdown?

@SLaks
Copy link
Collaborator

SLaks commented Mar 31, 2014

I have not been able to find any Markdown compiler which gives any kind of information about the source file.

(this is why I needed to write my own parser for the Markdown syntax highlighting)

@am11
Copy link
Contributor

am11 commented Mar 31, 2014

Not to my knowledge; no. We are using MarkdownSharp http://code.google.com/p/markdownsharp/ to compile markdown.

Once the compiler does the job, we don't have that kind of context to guess the definite mapping. Case in hand is SCSS compiler which generates incorrect map #828. No matter what we do, we just can't predict what went inside the compiler.

@lijunle
Copy link
Author

lijunle commented Mar 31, 2014

Is that project still alive? The latest commit is one year ago.

@am11
Copy link
Contributor

am11 commented Apr 1, 2014

Yes. It seems like dead.. Long shot: If CodePlex team has C# based markdown editor, maybe they can update it with V3 source maps.

@SLaks, (for preserving scroll position) is there a way to get the "first visible line number" of the view, if we don't have a tracking span?

In MarkdownMargin, we can get text host via TextViewMargin.CreateTextViewHost("markdown"); (marking CreateTextViewHost public) and hence host.TextView.

After that in MarkdownMargin.UpdateMargin, just before NavigateToString() is called, if we can cache the first line number of visible area, we can take the percentage.

For percentage scroll, we can do something like:

 _totalLines = Document.TextBuffer.CurrentSnapshot.LineCount;
_firstLineInCurrentVisibility =  ?;
_scrollPercentage = _currentLine * 100 / _totalLines;

_browser.NavigateToString(html); // this is asynchronous.

// .....
// after asynchronous operation completes and scroll position is disturbed, in callback:
// .....

_totalLines = Document.TextBuffer.CurrentSnapshot.LineCount;
int lineToNavigate = _scrollPercentage * _totalLines / 100;

for(int i = 0; i < lineToNavigate; ++I)
{
    _textView.TextView.ViewScroller.ScrollViewportVerticallyByLine(ScrollDirection.Down);
}

@SLaks
Copy link
Collaborator

SLaks commented Apr 1, 2014

We need to scroll the browser, not the editor.

@am11
Copy link
Contributor

am11 commented Apr 1, 2014

Cool. While looking into getting scroll position, I found this https://www.mail-archive.com/[email protected]/msg09449.html issue which pointed to another markdown editor for VS, which uses Chromium: https://github.com/Code52/DownmarkerWPF 😄

am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
am11 added a commit to am11/WebEssentials2013 that referenced this issue Apr 1, 2014
@am11
Copy link
Contributor

am11 commented Apr 1, 2014

Fixed by am11@515949d.

All those commits happened during cherry-picking and rebase'n... :(

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 a pull request may close this issue.

3 participants