Skip to content

Commit eeda926

Browse files
committed
feat(IParameter): Fixed setting, performance improve
1. Iparameter 2. Thread.Sleep 3. No lock
1 parent d46ecb7 commit eeda926

8 files changed

Lines changed: 218 additions & 83 deletions

File tree

SmoothScroll/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SmoothScroll
2+
3+
[![AppVeyor](https://img.shields.io/appveyor/ci/lkytal/smoothscroll.svg?style=flat-square)](https://ci.appveyor.com/project/lkytal/smoothscroll)
4+
5+
Smooth Scrolling for the Visual Studio 2013, 2015 and 2017.
6+
7+
Install [Smooth Scrolling](https://marketplace.visualstudio.com/items?itemName=lkytal.SmoothScroll) via Visual Studio market.
8+
9+
## VS2013 and VS2015 version
10+
11+
Install [the special version](SmoothScroll/SmoothScroll_VS2013.vsix).
12+
13+
## Additional features
14+
15+
* Hold shift key to Scroll horizontally.
16+
* Hold Alt key to scroll text view by one page up/down.
17+
18+
Let me know if you have questions or suggestions.
19+
20+
Preview:
21+
![ScreenShot](SmoothScroll/Resources/smooth.gif)
22+
23+
## Update Log
24+
25+
* 3.2.0: Fixed setting no effect
26+
* 3.1.4: Add FPS option
27+
* 3.1.4: Fixed Option Page
28+
* 3.1.1: Fixed MPF dependency
29+
* 3.1.0: Fixed load error for VS2017
30+
* 3.0.1: Last version for VS2013 and VS2015
31+
* 3.0.0: Use async package for VS2019
32+
* 2.9.0: Tentatively support VS2019.
33+
* 2.8.4: Tentatively support horizontal mouse wheel.
34+
* 2.8.3: Fix smooth option.
35+
* 2.8.2: Adjust initial duration.
36+
* 2.8.1: Adjust duration.
37+
* 2.8.0: Adjust parameters; Support different speed lever.
38+
* 2.7.0: Performance enhancement.
39+
* 2.6.0: Stop scroll when mouse click; no longer require reopening editor after setting changed.
40+
* 2.5.3: Fix horizontal scroll directing.
41+
* 2.5.2: Silent speed up when beginning.
42+
* 2.5.0: Support for Visual Studio 2017.
43+
* 2.4.0: Adaptive scroll duration.
44+
* 2.3.2: Fixup improper dispose.
45+
* 2.3.1: Better algorithm.
46+
* 2.2.0: Smooth scrolling when horizontally.
47+
* 2.1.1: Refined algorithm.
48+
* 2.1.0: More flexible settings.
49+
* 2.0.5: Fixup for VS2013.
50+
* 2.0.4: First stage fixup for VS2013.
51+
* 2.0.0: Option page and additional features.
52+
* 1.3.0: Experiment support for Visual Studio 15.
53+
* 1.2.0: Scrolling algorithm improved.
54+
* 1.1.0: Scrolling interval changed.
55+
56+
## My other extensions :
57+
58+
- ### [BuiltinCmd](https://marketplace.visualstudio.com/items?itemName=lkytal.BuiltinCmd)
59+
- ### [StatusInfo](https://marketplace.visualstudio.com/items?itemName=lkytal.StatusInfo)
60+
- ### [AutoZoom](https://marketplace.visualstudio.com/items?itemName=lkytal.AutoZoom)
61+
62+
## My HomePage
63+
64+
> [lkytal.github.io](https://lkytal.github.io)
65+
66+
## Acknowledgment
67+
68+
> <div>Icons made by <a href="http://www.flaticon.com/authors/vectors-market" title="Vectors Market">Vectors Market</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>
69+
70+
## Support on Beerpay
71+
Hey dude! Help me out for a couple of :beers:!
72+
73+
[![Beerpay](https://beerpay.io/lkytal/SmoothScroll/badge.svg?style=beer-square)](https://beerpay.io/lkytal/SmoothScroll) [![Beerpay](https://beerpay.io/lkytal/SmoothScroll/make-wish.svg?style=flat-square)](https://beerpay.io/lkytal/SmoothScroll?focus=wish)

SmoothScroll/SmoothScroll.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<None Include="app.config" />
121121
<None Include="Key.snk" />
122122
<None Include="packages.config" />
123+
<None Include="README.md" />
123124
<None Include="source.extension.vsixmanifest">
124125
<SubType>Designer</SubType>
125126
</None>

SmoothScroll/SmoothScrollProcessor.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
namespace SmoothScroll
1111
{
12-
internal sealed class SmoothScrollProcessor : MouseProcessorBase
12+
internal sealed class SmoothScrollProcessor : MouseProcessorBase, IParameters
1313
{
14+
public ScrollingSpeeds SpeedLever => SmoothScrollPackage.OptionsPage?.DurationRatio ?? ScrollingSpeeds.Normal;
15+
public ScrollingFPS FPS => SmoothScrollPackage.OptionsPage?.FPS ?? ScrollingFPS.High;
16+
1417
private const int WM_MOUSEHWHEEL = 0x020E;
1518

1619
private readonly IWpfTextView wpfTextView;
@@ -20,17 +23,15 @@ internal sealed class SmoothScrollProcessor : MouseProcessorBase
2023
private bool AltEnable => SmoothScrollPackage.OptionsPage?.AltEnable ?? true;
2124
private bool SmoothEnable => SmoothScrollPackage.OptionsPage?.SmoothEnable ?? true;
2225
private double DistanceRatio => SmoothScrollPackage.OptionsPage?.DistanceRatio ?? 1.1;
23-
private ScrollingSpeeds SpeedLever => SmoothScrollPackage.OptionsPage?.DurationRatio ?? ScrollingSpeeds.Normal;
24-
private ScrollingFPS FPS => SmoothScrollPackage.OptionsPage?.FPS ?? ScrollingFPS.High;
2526

2627
private readonly ScrollController verticalController, horizontalController;
2728

2829
internal SmoothScrollProcessor(IWpfTextView _wpfTextView)
2930
{
3031
this.wpfTextView = _wpfTextView;
3132
var pageScroller = new PageScroller(wpfTextView);
32-
verticalController = new ScrollController(pageScroller, ScrollingDirection.Vertical, FPS);
33-
horizontalController = new ScrollController(pageScroller, ScrollingDirection.Horizontal, FPS);
33+
verticalController = new ScrollController(pageScroller, this, ScrollingDirection.Vertical);
34+
horizontalController = new ScrollController(pageScroller, this, ScrollingDirection.Horizontal);
3435

3536
wpfTextView.VisualElement.Loaded += (_, __) =>
3637
{
@@ -79,7 +80,7 @@ private void PostScrollRequest(double distance, ScrollingDirection direction)
7980
{
8081
if (SmoothEnable && NativeMethods.IsMouseEvent())
8182
{
82-
verticalController.ScrollView(distance * DistanceRatio, SpeedLever);
83+
verticalController.ScrollView(distance * DistanceRatio);
8384
}
8485
else
8586
{
@@ -90,7 +91,7 @@ private void PostScrollRequest(double distance, ScrollingDirection direction)
9091
{
9192
if (SmoothEnable && NativeMethods.IsMouseEvent())
9293
{
93-
horizontalController.ScrollView(distance * DistanceRatio, SpeedLever);
94+
horizontalController.ScrollView(distance * DistanceRatio);
9495
}
9596
else
9697
{

SmoothScroll/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="C3E3372B-022D-4E19-BD83-EEDD6FA01E5C" Version="3.1.5" Language="en-US" Publisher="Lkytal" />
4+
<Identity Id="C3E3372B-022D-4E19-BD83-EEDD6FA01E5C" Version="3.2.0" Language="en-US" Publisher="Lkytal" />
55
<DisplayName>Smooth Scroll</DisplayName>
66
<Description xml:space="preserve">Smooth Scroll for VS2017 and VS2019</Description>
77
<MoreInfo>https://github.com/lkytal/SmoothScroll</MoreInfo>

TestWpf/MainWindow.xaml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<Window x:Class="TestWpf.MainWindow"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:local="clr-namespace:TestWpf"
7-
mc:Ignorable="d"
8-
Title="MainWindow" Height="600" Width="600" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:TestWpf"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="600" Width="600" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
99
<Grid>
1010
<Grid.ColumnDefinitions>
11-
<ColumnDefinition Width="997*"/>
11+
<ColumnDefinition Width="auto"/>
1212
<ColumnDefinition Width="195*"/>
1313
</Grid.ColumnDefinitions>
1414
<Grid.RowDefinitions>
15+
<RowDefinition Height="auto" />
1516
<RowDefinition Height="auto" />
1617
<RowDefinition Height="*" />
1718
</Grid.RowDefinitions>
@@ -21,6 +22,16 @@
2122
<RadioButton x:Name="radioNormal" Padding="10" Content="Normal" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" IsChecked="True"></RadioButton>
2223
<RadioButton x:Name="radioFast" Padding="10" Content="Fast" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center"></RadioButton>
2324
</StackPanel>
24-
<TextBox x:Name="textBox" Grid.Row="1" TextWrapping="NoWrap" HorizontalContentAlignment="Stretch" FontFamily="Consolas" FontSize="14" HorizontalScrollBarVisibility="Visible" Grid.ColumnSpan="2"/>
25+
26+
27+
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0" Grid.ColumnSpan="2">
28+
<RadioButton x:Name="fvslow" Padding="10" VerticalContentAlignment="Center" Content="Very Slow" HorizontalContentAlignment="Stretch"/>
29+
<RadioButton x:Name="fslow" Padding="10" Content="Slow" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center"></RadioButton>
30+
<RadioButton x:Name="fnormal" Padding="10" VerticalContentAlignment="Center" Content="Normal" HorizontalContentAlignment="Stretch" IsChecked="True"/>
31+
<RadioButton x:Name="ffast" Padding="10" Content="Fast" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center"></RadioButton>
32+
<RadioButton x:Name="fvfast" Padding="10" Content="Very Fast" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center"></RadioButton>
33+
</StackPanel>
34+
35+
<TextBox x:Name="textBox" Grid.Row="2" TextWrapping="NoWrap" HorizontalContentAlignment="Stretch" FontFamily="Consolas" FontSize="14" HorizontalScrollBarVisibility="Visible" Grid.ColumnSpan="2"/>
2536
</Grid>
2637
</Window>

TestWpf/MainWindow.xaml.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ namespace TestWpf
2121
/// <summary>
2222
/// MainWindow.xaml 的交互逻辑
2323
/// </summary>
24-
public partial class MainWindow : Window, IPageScroller
24+
public partial class MainWindow : Window, IPageScroller, IParameters
2525
{
26+
public ScrollingSpeeds SpeedLever { get; set; }
27+
public ScrollingFPS FPS { get; set; }
28+
2629
private const int WM_MOUSEHWHEEL = 0x020E;
2730
private ScrollController vscrollController;
2831
private ScrollController hscrollController;
@@ -34,8 +37,8 @@ public MainWindow()
3437

3538
private void Window_Loaded(object sender, RoutedEventArgs e)
3639
{
37-
vscrollController = new ScrollController(this, ScrollingDirection.Vertical, ScrollingFPS.High);
38-
hscrollController = new ScrollController(this, ScrollingDirection.Horizontal, ScrollingFPS.High);
40+
vscrollController = new ScrollController(this, this, ScrollingDirection.Vertical);
41+
hscrollController = new ScrollController(this, this, ScrollingDirection.Horizontal);
3942
textBox.PreviewMouseWheel += textBox_PreviewMouseWheel;
4043
HwndSource source = PresentationSource.FromVisual(textBox) as HwndSource;
4144
source?.AddHook(textBox_Hook);
@@ -69,18 +72,41 @@ public void Scroll(ScrollingDirection direction, double value)
6972

7073
private void Scroll(int delta, ScrollController controller)
7174
{
72-
var scrollingSpeeds = ScrollingSpeeds.Normal;
73-
7475
if (radioSlow.IsChecked ?? false)
7576
{
76-
scrollingSpeeds = ScrollingSpeeds.Slow;
77+
SpeedLever = ScrollingSpeeds.Slow;
7778
}
7879
else if (radioFast.IsChecked ?? false)
7980
{
80-
scrollingSpeeds = ScrollingSpeeds.Fast;
81+
SpeedLever = ScrollingSpeeds.Fast;
82+
}
83+
else
84+
{
85+
SpeedLever = ScrollingSpeeds.Normal;
86+
}
87+
88+
if (fvslow.IsChecked ?? false)
89+
{
90+
FPS = ScrollingFPS.Very_Low;
91+
}
92+
else if (fslow.IsChecked ?? false)
93+
{
94+
FPS = ScrollingFPS.Low;
95+
}
96+
else if (fnormal.IsChecked ?? false)
97+
{
98+
FPS = ScrollingFPS.Normal;
99+
}
100+
else if (ffast.IsChecked ?? false)
101+
{
102+
FPS = ScrollingFPS.High;
103+
}
104+
else if (fvfast.IsChecked ?? false)
105+
{
106+
FPS = ScrollingFPS.Very_High;
81107
}
82108

83-
controller.ScrollView(delta, scrollingSpeeds);
109+
controller.ScrollView(delta);
84110
}
85111

86112
private void textBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)

scrollController/IPageScroller.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ public interface IPageScroller
55
void Scroll(ScrollingDirection direction, double value);
66
}
77

8+
public interface IParameters
9+
{
10+
ScrollingSpeeds SpeedLever { get; }
11+
ScrollingFPS FPS { get; }
12+
}
13+
814
public enum ScrollingSpeeds
915
{
1016
Slow = 1,
1117
Normal = 2,
12-
Fast = 3
18+
Fast = 3,
19+
Very_Fast = 4,
1320
}
1421

1522
public enum ScrollingDirection
@@ -20,10 +27,10 @@ public enum ScrollingDirection
2027
}
2128
public enum ScrollingFPS
2229
{
23-
None,
24-
Low = 1,
25-
Normal = 2,
26-
High = 3,
27-
Very_High = 4,
30+
Very_Low = 1,
31+
Low = 2,
32+
Normal = 3,
33+
High = 4,
34+
Very_High = 5,
2835
}
2936
}

0 commit comments

Comments
 (0)