Skip to content

Commit

Permalink
Merge pull request Code52#27 from Code52/DelayedScrolling
Browse files Browse the repository at this point in the history
Editing doesn't lose your place, and doesn't jumpy scroll be using a delay
  • Loading branch information
andrewtobin committed Jan 6, 2012
2 parents 0de16b5 + 40baa22 commit f94e777
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/MarkPad/Document/DocumentView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ private void DocumentViewLoaded(object sender, RoutedEventArgs e)
if (documentScrollViewer != null)
{
documentScrollViewer.ScrollChanged += (i, j) => wb.ExecuteJavascript("window.scrollTo(0," + j.VerticalOffset + ");");
var x = ((DocumentViewModel)DataContext);
x.Document.TextChanged += (i, j) =>
{
wb.LoadCompleted += (k, l) => wb.ExecuteJavascript("window.scrollTo(0," + documentScrollViewer.VerticalOffset + ");");
};
}
}


}

public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
{
Expand All @@ -56,4 +62,6 @@ public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObj
return null;
}
}


}
20 changes: 15 additions & 5 deletions src/MarkPad/Document/DocumentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO;
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Threading;
using Caliburn.Micro;
using ICSharpCode.AvalonEdit.Document;
using MarkdownSharp;
Expand All @@ -11,19 +13,26 @@ namespace MarkPad.Document
internal class DocumentViewModel : Screen
{
private readonly IDialogService dialogService;

private string title;
private string filename;
private readonly TimeSpan delay = TimeSpan.FromSeconds(0.5);
private readonly DispatcherTimer timer;

public DocumentViewModel(IDialogService dialogService)
{
this.dialogService = dialogService;

title = "New Document";
Original = "";
Document = new TextDocument();
timer = new DispatcherTimer();
timer.Tick += TimerTick;
timer.Interval = delay;
}
private void TimerTick(object sender, EventArgs e)
{
timer.Stop();
NotifyOfPropertyChange(() => Render);
}

public void Open(string path)
{
filename = path;
Expand All @@ -36,7 +45,8 @@ public void Open(string path)

public void Update()
{
NotifyOfPropertyChange(() => Render);
timer.Stop();
timer.Start();
NotifyOfPropertyChange(() => HasChanges);
NotifyOfPropertyChange(() => DisplayName);
}
Expand Down

0 comments on commit f94e777

Please sign in to comment.