mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
More natural scroll behaviour
This commit is contained in:
@@ -11,6 +11,6 @@
|
||||
UseLayoutRounding="True">
|
||||
<Grid>
|
||||
<avalonEdit:TextEditor x:Name="viewer" Background="#00FFFFFF" FontSize="14" ShowLineNumbers="True"
|
||||
WordWrap="True" IsReadOnly="True" />
|
||||
WordWrap="True" IsReadOnly="True" IsManipulationEnabled="True" />
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -18,6 +18,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
|
||||
@@ -32,12 +33,48 @@ namespace QuickLook.Plugin.TextViewer
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
viewer.ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting;
|
||||
viewer.ManipulationStarting += Viewer_ManipulationStarting;
|
||||
viewer.ManipulationDelta += Viewer_ManipulationDelta;
|
||||
|
||||
viewer.PreviewMouseWheel += Viewer_MouseWheel;
|
||||
|
||||
viewer.FontFamily =
|
||||
new FontFamily(context.GetString("Editor_FontFamily", failsafe: "Consolas"));
|
||||
|
||||
LoadFile(path);
|
||||
}
|
||||
|
||||
private void Viewer_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
|
||||
{
|
||||
e.TranslationBehavior = new InertiaTranslationBehavior
|
||||
{
|
||||
InitialVelocity = e.InitialVelocities.LinearVelocity,
|
||||
DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0)
|
||||
};
|
||||
}
|
||||
|
||||
private void Viewer_MouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
viewer.ScrollToVerticalOffset(viewer.VerticalOffset - e.Delta);
|
||||
}
|
||||
|
||||
private void Viewer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
var delta = e.DeltaManipulation;
|
||||
viewer.ScrollToVerticalOffset(viewer.VerticalOffset - delta.Translation.Y);
|
||||
}
|
||||
|
||||
private void Viewer_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
|
||||
{
|
||||
e.ManipulationContainer = this;
|
||||
e.Mode = ManipulationModes.Translate;
|
||||
}
|
||||
|
||||
private void LoadFile(string path)
|
||||
{
|
||||
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
|
Reference in New Issue
Block a user