Permalink
Browse files

Editing doesn't lose your place, and doesn't jumpy scroll be using a …

…delay.
  • Loading branch information...
1 parent 0de16b5 commit 40baa22f8ceab56d3bdb5ba7c5baac7648b9a1b3 aeoth committed Jan 6, 2012
Showing with 24 additions and 6 deletions.
  1. +9 −1 src/MarkPad/Document/DocumentView.xaml.cs
  2. +15 −5 src/MarkPad/Document/DocumentViewModel.cs
@@ -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
{
@@ -56,4 +62,6 @@ private void DocumentViewLoaded(object sender, RoutedEventArgs e)
return null;
}
}
+
+
}
@@ -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;
@@ -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;
@@ -36,7 +45,8 @@ public void Open(string path)
public void Update()
{
- NotifyOfPropertyChange(() => Render);
+ timer.Stop();
+ timer.Start();
NotifyOfPropertyChange(() => HasChanges);
NotifyOfPropertyChange(() => DisplayName);
}

0 comments on commit 40baa22

Please sign in to comment.