Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@ namespace EasyMotion.Implementation.Adornment
{
internal sealed class EasyMotionAdornmentController : IEasyMotionNavigator
{
private static readonly string[] NavigationKeys =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
private static string[] GenerateNavigationMultiKeys()
{
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
string[] s = new string[alphabet.Length * alphabet.Length];
int k = 0;
for (int i = 0; i < alphabet.Length; i++)
{
for (int j = 0; j < alphabet.Length; j++)
{
char[] letters = { alphabet[i], alphabet[j] };
s[k] = new string(letters);
k++;
}
}
return s;
}

private static readonly string[] NavigationMultiKeys = GenerateNavigationMultiKeys();
private static readonly string[] NavigationSingleKeys =
"abcdefghijklmnopqrstuvwxyz"
.Select(x => x.ToString())
.ToArray();

Expand Down Expand Up @@ -102,6 +120,19 @@ private void AddAdornments()
var endPoint = textViewLines.LastVisibleLine.End;
var snapshot = startPoint.Snapshot;
int navigateIndex = 0;

for (int i = startPoint.Position; i < endPoint.Position; i++)
{
var point = new SnapshotPoint(snapshot, i);
if (Char.ToLower(point.GetChar()) == Char.ToLower(_easyMotionUtil.TargetChar))
{
navigateIndex++;
}
}

string[] NavigationKeys = navigateIndex < NavigationSingleKeys.Length ? NavigationSingleKeys : NavigationMultiKeys;
navigateIndex = 0;

for (int i = startPoint.Position; i < endPoint.Position; i++)
{
var point = new SnapshotPoint(snapshot, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal sealed class EasyMotionKeyProcessor : KeyProcessor
{
private readonly IEasyMotionUtil _easyMotionUtil;
private readonly IEasyMotionNavigator _easyMotionNavigator;
private System.Text.StringBuilder _easyMotionLettersAccumulator = new System.Text.StringBuilder();

internal EasyMotionKeyProcessor(IEasyMotionUtil easyMotionUtil, IEasyMotionNavigator easyMotionNavigator)
{
Expand Down Expand Up @@ -49,6 +50,7 @@ public override void KeyUp(KeyEventArgs args)

if (args.Key == Key.Escape && _easyMotionUtil.State != EasyMotionState.Disabled)
{
//_userInput = string.Empty;
_easyMotionUtil.ChangeToDisabled();
}
}
Expand All @@ -58,6 +60,7 @@ private void TextInputLookingForChar(TextCompositionEventArgs args)
if (args.Text.Length == 1)
{
_easyMotionUtil.ChangeToLookingForDecision(args.Text[0]);
_easyMotionLettersAccumulator.Clear();
args.Handled = true;
}
}
Expand All @@ -66,7 +69,8 @@ private void TextInputLookingForDecision(TextCompositionEventArgs args)
{
if (args.Text.Length > 0)
{
if (_easyMotionNavigator.NavigateTo(args.Text))
_easyMotionLettersAccumulator.Append(args.Text);
if (_easyMotionNavigator.NavigateTo(_easyMotionLettersAccumulator.ToString()))
{
_easyMotionUtil.ChangeToDisabled();
}
Expand Down