From 5cb89c1041997bb73f9a7ec76b48328760754e9a Mon Sep 17 00:00:00 2001 From: Marias Marcell Date: Mon, 16 Oct 2017 23:07:51 +0200 Subject: [PATCH 1/5] Restructuring the code to provide word searching capability --- .gitignore | 3 ++ EasyMotion/EasyMotionPackage.cs | 2 +- EasyMotion/IEasyMotionUtil.cs | 19 +++++++++++- .../EasyMotionAdornmentController.cs | 30 ++++++++++++++----- .../Adornment/EasyMotionAdornmentFactory.cs | 10 +++++-- .../EasyMotionUtil/EasyMotionUtil.cs | 12 ++++++-- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 2feec09..8467e85 100644 --- a/.gitignore +++ b/.gitignore @@ -173,3 +173,6 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ +*.ide +/.vs/slnx.sqlite +/.vs/VSWorkspaceState.json diff --git a/EasyMotion/EasyMotionPackage.cs b/EasyMotion/EasyMotionPackage.cs index e95fc09..2578e3f 100644 --- a/EasyMotion/EasyMotionPackage.cs +++ b/EasyMotion/EasyMotionPackage.cs @@ -81,7 +81,7 @@ private void MenuItemCallback(object sender, EventArgs e) } else { - easyMotionUtil.ChangeToLookingForChar(); + easyMotionUtil.ChangeToLookingForChar(EasyMotionSearchMode.Char); } } diff --git a/EasyMotion/IEasyMotionUtil.cs b/EasyMotion/IEasyMotionUtil.cs index 12e972a..a2d7107 100644 --- a/EasyMotion/IEasyMotionUtil.cs +++ b/EasyMotion/IEasyMotionUtil.cs @@ -7,6 +7,21 @@ namespace EasyMotion { + internal enum EasyMotionSearchMode + { + /// + /// Developer is looking for characters anywhere + /// + Char, + + /// + /// Developer is looking for words starting with the typed character + /// + Word + } + + + internal enum EasyMotionState { /// @@ -37,6 +52,8 @@ internal interface IEasyMotionUtil EasyMotionState State { get; } + EasyMotionSearchMode SearchMode { get; } + /// /// During the LookingForDecision state this will be the character which /// the user has decided to make an easy motion for @@ -47,7 +64,7 @@ internal interface IEasyMotionUtil void ChangeToDisabled(); - void ChangeToLookingForChar(); + void ChangeToLookingForChar(EasyMotionSearchMode searchMode); void ChangeToLookingForDecision(char target); diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs index 4a786a2..5f8708c 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs @@ -10,6 +10,7 @@ using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; using System.Windows; +using Microsoft.VisualStudio.Text.Operations; namespace EasyMotion.Implementation.Adornment { @@ -24,16 +25,19 @@ internal sealed class EasyMotionAdornmentController : IEasyMotionNavigator private readonly IWpfTextView _wpfTextView; private readonly IEditorFormatMap _editorFormatMap; private readonly IClassificationFormatMap _classificationFormatMap; + private readonly ITextSearchService _TextSerachService; private readonly Dictionary _navigateMap = new Dictionary(); private readonly object _tag = new object(); private IAdornmentLayer _adornmentLayer; - internal EasyMotionAdornmentController(IEasyMotionUtil easyMotionUtil, IWpfTextView wpfTextview, IEditorFormatMap editorFormatMap, IClassificationFormatMap classificationFormatMap) + internal EasyMotionAdornmentController(IEasyMotionUtil easyMotionUtil, IWpfTextView wpfTextview, IEditorFormatMap editorFormatMap, IClassificationFormatMap classificationFormatMap + , ITextSearchService _textSerachService) { _easyMotionUtil = easyMotionUtil; _wpfTextView = wpfTextview; _editorFormatMap = editorFormatMap; _classificationFormatMap = classificationFormatMap; + _TextSerachService = _textSerachService; } internal void SetAdornmentLayer(IAdornmentLayer adornmentLayer) @@ -102,18 +106,28 @@ 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 toSearch = _easyMotionUtil.TargetChar.ToString(); + var data = new FindData() { - var point = new SnapshotPoint(snapshot, i); + SearchString = _easyMotionUtil.SearchMode == EasyMotionSearchMode.Char ? toSearch : @"\b" + toSearch, + TextSnapshotToSearch = snapshot, + FindOptions = FindOptions.UseRegularExpressions + }; - if (Char.ToLower(point.GetChar()) == Char.ToLower(_easyMotionUtil.TargetChar) && navigateIndex < NavigationKeys.Length) + var startindex = startPoint.Position; + while (navigateIndex < NavigationKeys.Length) + { + var res = _TextSerachService.FindNext(startindex, false, data); + if (!res.HasValue) { - string key = NavigationKeys[navigateIndex]; - navigateIndex++; - AddNavigateToPoint(textViewLines, point, key); + break; } + var key = NavigationKeys[navigateIndex]; + AddNavigateToPoint(textViewLines, res.Value.Start, key); + startindex = res.Value.Start.Position + 1; + navigateIndex++; } - if (navigateIndex == 0) { _easyMotionUtil.ChangeToLookingCharNotFound(); diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs index 563d803..077323d 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualStudio.Text.Operations; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; @@ -25,6 +26,7 @@ internal sealed class EasyMotionAdornmentFactory : IWpfTextViewCreationListener, private readonly IEasyMotionUtilProvider _easyMotionUtilProvider; private readonly IEditorFormatMapService _editorFormatMapService; private readonly IClassificationFormatMapService _classificationFormatMapService; + private readonly ITextSearchService _textSerachService; #pragma warning disable 169 [Export(typeof(AdornmentLayerDefinition))] @@ -34,11 +36,13 @@ internal sealed class EasyMotionAdornmentFactory : IWpfTextViewCreationListener, #pragma warning restore 169 [ImportingConstructor] - internal EasyMotionAdornmentFactory(IEasyMotionUtilProvider easyMotionUtilProvider, IEditorFormatMapService editorFormatMapService, IClassificationFormatMapService classificationFormatMapService) + internal EasyMotionAdornmentFactory(IEasyMotionUtilProvider easyMotionUtilProvider, IEditorFormatMapService editorFormatMapService + , IClassificationFormatMapService classificationFormatMapService, ITextSearchService textSearchService) { _easyMotionUtilProvider = easyMotionUtilProvider; _editorFormatMapService = editorFormatMapService; _classificationFormatMapService = classificationFormatMapService; + _textSerachService = textSearchService; } private EasyMotionAdornmentController GetOrCreate(IWpfTextView wpfTextView) @@ -50,7 +54,7 @@ private EasyMotionAdornmentController GetOrCreate(IWpfTextView wpfTextView) var easyMotionUtil = _easyMotionUtilProvider.GetEasyMotionUtil(wpfTextView); var editorFormatMap = _editorFormatMapService.GetEditorFormatMap(wpfTextView); var classificationFormatMap = _classificationFormatMapService.GetClassificationFormatMap(wpfTextView); - return new EasyMotionAdornmentController(easyMotionUtil, wpfTextView, editorFormatMap, classificationFormatMap); + return new EasyMotionAdornmentController(easyMotionUtil, wpfTextView, editorFormatMap, classificationFormatMap, _textSerachService); }); } diff --git a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs index 46f8b77..ad4cc81 100644 --- a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs +++ b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualStudio.Shell.Interop; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -11,6 +12,7 @@ internal sealed class EasyMotionUtil : IEasyMotionUtil { private readonly ITextView _textView; private EasyMotionState _state; + private EasyMotionSearchMode _searchMode; private char _targetChar; public EasyMotionState State @@ -18,6 +20,11 @@ public EasyMotionState State get { return _state; } } + public EasyMotionSearchMode SearchMode + { + get { return _searchMode; } + } + public char TargetChar { get { return _targetChar; } @@ -43,9 +50,10 @@ public void ChangeToDisabled() RaiseStateChanged(); } - public void ChangeToLookingForChar() + public void ChangeToLookingForChar(EasyMotionSearchMode mode) { _state = EasyMotionState.LookingForChar; + _searchMode = mode; _targetChar = (char)0; RaiseStateChanged(); } From f57583ce6ae782539bd8dc3ace526fa71bdc9845 Mon Sep 17 00:00:00 2001 From: Marias Marcell Date: Mon, 16 Oct 2017 23:37:46 +0200 Subject: [PATCH 2/5] Adding navigate to word command --- EasyMotion/EasyMotion.vsct | 10 +++++++++- EasyMotion/EasyMotionPackage.cs | 9 ++++++++- EasyMotion/PkgCmdID.cs | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/EasyMotion/EasyMotion.vsct b/EasyMotion/EasyMotion.vsct index cda51e6..2556bdc 100644 --- a/EasyMotion/EasyMotion.vsct +++ b/EasyMotion/EasyMotion.vsct @@ -14,13 +14,20 @@ + @@ -40,6 +47,7 @@ + diff --git a/EasyMotion/EasyMotionPackage.cs b/EasyMotion/EasyMotionPackage.cs index 2578e3f..df9d2c0 100644 --- a/EasyMotion/EasyMotionPackage.cs +++ b/EasyMotion/EasyMotionPackage.cs @@ -60,6 +60,10 @@ protected override void Initialize() CommandID menuCommandID = new CommandID(GuidList.guidEasyMotionCmdSet, (int)PkgCmdIDList.CmdEasyMotionNavigate); MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID ); mcs.AddCommand( menuItem ); + // Navigate to word + menuCommandID = new CommandID(GuidList.guidEasyMotionCmdSet, (int)PkgCmdIDList.CmdEasyMotionNavigateWord); + menuItem = new MenuCommand(MenuItemCallback, menuCommandID); + mcs.AddCommand(menuItem); } } @@ -81,7 +85,10 @@ private void MenuItemCallback(object sender, EventArgs e) } else { - easyMotionUtil.ChangeToLookingForChar(EasyMotionSearchMode.Char); + var command = sender as MenuCommand; + Debug.Assert(command != null); + var mode = command.CommandID.ID == PkgCmdIDList.CmdEasyMotionNavigateWord ? EasyMotionSearchMode.Word : EasyMotionSearchMode.Char; + easyMotionUtil.ChangeToLookingForChar(mode); } } diff --git a/EasyMotion/PkgCmdID.cs b/EasyMotion/PkgCmdID.cs index 46690e4..020cd3b 100644 --- a/EasyMotion/PkgCmdID.cs +++ b/EasyMotion/PkgCmdID.cs @@ -7,7 +7,7 @@ namespace EasyMotion static class PkgCmdIDList { public const uint CmdEasyMotionNavigate = 0x100; - + public const uint CmdEasyMotionNavigateWord = 0x101; }; } \ No newline at end of file From 67d0f68e18945ef1fe229ec538a24ac64ff43c18 Mon Sep 17 00:00:00 2001 From: Marcell Marias Date: Tue, 17 Oct 2017 12:57:37 +0200 Subject: [PATCH 3/5] Adding *Extend commands --- EasyMotion/EasyMotion.vsct | 21 ++++++++++ EasyMotion/EasyMotionPackage.cs | 38 ++++++++++++++----- EasyMotion/IEasyMotionUtil.cs | 12 +++++- .../EasyMotionAdornmentController.cs | 17 +++++++-- .../Adornment/EasyMotionAdornmentFactory.cs | 6 ++- .../EasyMotionUtil/EasyMotionUtil.cs | 3 +- EasyMotion/PkgCmdID.cs | 8 ++-- 7 files changed, 83 insertions(+), 22 deletions(-) diff --git a/EasyMotion/EasyMotion.vsct b/EasyMotion/EasyMotion.vsct index 2556bdc..0328a0a 100644 --- a/EasyMotion/EasyMotion.vsct +++ b/EasyMotion/EasyMotion.vsct @@ -28,7 +28,26 @@ .EasyMotion.NavigateWord + + + + + @@ -48,6 +67,8 @@ + + diff --git a/EasyMotion/EasyMotionPackage.cs b/EasyMotion/EasyMotionPackage.cs index df9d2c0..7423490 100644 --- a/EasyMotion/EasyMotionPackage.cs +++ b/EasyMotion/EasyMotionPackage.cs @@ -53,20 +53,23 @@ protected override void Initialize() _exportProvider = _componentModel.DefaultExportProvider; // Add our command handlers for menu (commands must exist in the .vsct file) - OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; + var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if ( null != mcs ) { - // Create the command for the menu item. - CommandID menuCommandID = new CommandID(GuidList.guidEasyMotionCmdSet, (int)PkgCmdIDList.CmdEasyMotionNavigate); - MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID ); - mcs.AddCommand( menuItem ); - // Navigate to word - menuCommandID = new CommandID(GuidList.guidEasyMotionCmdSet, (int)PkgCmdIDList.CmdEasyMotionNavigateWord); - menuItem = new MenuCommand(MenuItemCallback, menuCommandID); - mcs.AddCommand(menuItem); + AddCommand(PkgCmdIDList.CmdEasyMotionNavigate, mcs); + AddCommand(PkgCmdIDList.CmdEasyMotionNavigateWord, mcs); + AddCommand(PkgCmdIDList.CmdEasyMotionNavigateExtend, mcs); + AddCommand(PkgCmdIDList.CmdEasyMotionNavigateWordExtend, mcs); } } + private void AddCommand(uint cmd, OleMenuCommandService mcs) + { + var menuCommandID = new CommandID(GuidList.guidEasyMotionCmdSet, (int)cmd); + var menuItem = new MenuCommand(MenuItemCallback, menuCommandID); + mcs.AddCommand(menuItem); + } + private void MenuItemCallback(object sender, EventArgs e) { ITextView textView; @@ -87,7 +90,22 @@ private void MenuItemCallback(object sender, EventArgs e) { var command = sender as MenuCommand; Debug.Assert(command != null); - var mode = command.CommandID.ID == PkgCmdIDList.CmdEasyMotionNavigateWord ? EasyMotionSearchMode.Word : EasyMotionSearchMode.Char; + var mode = EasyMotionSearchMode.Char; + switch (command.CommandID.ID) + { + case (int)PkgCmdIDList.CmdEasyMotionNavigate: + mode = EasyMotionSearchMode.Char; + break; + case (int)PkgCmdIDList.CmdEasyMotionNavigateWord: + mode = EasyMotionSearchMode.Word; + break; + case (int)PkgCmdIDList.CmdEasyMotionNavigateExtend: + mode = EasyMotionSearchMode.CharExtend; + break; + case (int)PkgCmdIDList.CmdEasyMotionNavigateWordExtend: + mode = EasyMotionSearchMode.WordExtend; + break; + } easyMotionUtil.ChangeToLookingForChar(mode); } } diff --git a/EasyMotion/IEasyMotionUtil.cs b/EasyMotion/IEasyMotionUtil.cs index a2d7107..9a23d25 100644 --- a/EasyMotion/IEasyMotionUtil.cs +++ b/EasyMotion/IEasyMotionUtil.cs @@ -17,7 +17,17 @@ internal enum EasyMotionSearchMode /// /// Developer is looking for words starting with the typed character /// - Word + Word, + + /// + /// Same as Char + extending the selection + /// + CharExtend, + + /// + /// Same as Word + extending the selection + /// + WordExtend } diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs index 5f8708c..bdab7cb 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs @@ -26,18 +26,20 @@ internal sealed class EasyMotionAdornmentController : IEasyMotionNavigator private readonly IEditorFormatMap _editorFormatMap; private readonly IClassificationFormatMap _classificationFormatMap; private readonly ITextSearchService _TextSerachService; + private readonly IEditorOperations _editorOperations; private readonly Dictionary _navigateMap = new Dictionary(); private readonly object _tag = new object(); private IAdornmentLayer _adornmentLayer; internal EasyMotionAdornmentController(IEasyMotionUtil easyMotionUtil, IWpfTextView wpfTextview, IEditorFormatMap editorFormatMap, IClassificationFormatMap classificationFormatMap - , ITextSearchService _textSerachService) + , ITextSearchService textSerachService, IEditorOperations editorOperations) { _easyMotionUtil = easyMotionUtil; _wpfTextView = wpfTextview; _editorFormatMap = editorFormatMap; _classificationFormatMap = classificationFormatMap; - _TextSerachService = _textSerachService; + _TextSerachService = textSerachService; + _editorOperations = editorOperations; } internal void SetAdornmentLayer(IAdornmentLayer adornmentLayer) @@ -119,7 +121,7 @@ private void AddAdornments() while (navigateIndex < NavigationKeys.Length) { var res = _TextSerachService.FindNext(startindex, false, data); - if (!res.HasValue) + if (!res.HasValue || res.Value.Start.Position > endPoint.Position) { break; } @@ -170,7 +172,14 @@ public bool NavigateTo(string key) return false; } - _wpfTextView.Caret.MoveTo(point); + if (_easyMotionUtil.SearchMode == EasyMotionSearchMode.CharExtend || _easyMotionUtil.SearchMode == EasyMotionSearchMode.WordExtend) + { + _editorOperations.ExtendSelection(point.Position); + } + else + { + _wpfTextView.Caret.MoveTo(point); + } return true; } } diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs index 077323d..0c6bcf3 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentFactory.cs @@ -27,6 +27,7 @@ internal sealed class EasyMotionAdornmentFactory : IWpfTextViewCreationListener, private readonly IEditorFormatMapService _editorFormatMapService; private readonly IClassificationFormatMapService _classificationFormatMapService; private readonly ITextSearchService _textSerachService; + private readonly IEditorOperationsFactoryService _editorOperationsFactory; #pragma warning disable 169 [Export(typeof(AdornmentLayerDefinition))] @@ -37,12 +38,13 @@ internal sealed class EasyMotionAdornmentFactory : IWpfTextViewCreationListener, [ImportingConstructor] internal EasyMotionAdornmentFactory(IEasyMotionUtilProvider easyMotionUtilProvider, IEditorFormatMapService editorFormatMapService - , IClassificationFormatMapService classificationFormatMapService, ITextSearchService textSearchService) + , IClassificationFormatMapService classificationFormatMapService, ITextSearchService textSearchService, IEditorOperationsFactoryService editorOperations) { _easyMotionUtilProvider = easyMotionUtilProvider; _editorFormatMapService = editorFormatMapService; _classificationFormatMapService = classificationFormatMapService; _textSerachService = textSearchService; + _editorOperationsFactory = editorOperations; } private EasyMotionAdornmentController GetOrCreate(IWpfTextView wpfTextView) @@ -54,7 +56,7 @@ private EasyMotionAdornmentController GetOrCreate(IWpfTextView wpfTextView) var easyMotionUtil = _easyMotionUtilProvider.GetEasyMotionUtil(wpfTextView); var editorFormatMap = _editorFormatMapService.GetEditorFormatMap(wpfTextView); var classificationFormatMap = _classificationFormatMapService.GetClassificationFormatMap(wpfTextView); - return new EasyMotionAdornmentController(easyMotionUtil, wpfTextView, editorFormatMap, classificationFormatMap, _textSerachService); + return new EasyMotionAdornmentController(easyMotionUtil, wpfTextView, editorFormatMap, classificationFormatMap, _textSerachService, _editorOperationsFactory.GetEditorOperations(wpfTextView)); }); } diff --git a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs index ad4cc81..cf13015 100644 --- a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs +++ b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs @@ -1,5 +1,4 @@ -using Microsoft.VisualStudio.Shell.Interop; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/EasyMotion/PkgCmdID.cs b/EasyMotion/PkgCmdID.cs index 020cd3b..4f22b08 100644 --- a/EasyMotion/PkgCmdID.cs +++ b/EasyMotion/PkgCmdID.cs @@ -6,8 +6,10 @@ namespace EasyMotion { static class PkgCmdIDList { - public const uint CmdEasyMotionNavigate = 0x100; - public const uint CmdEasyMotionNavigateWord = 0x101; + public const uint CmdEasyMotionNavigate = 0x100; + public const uint CmdEasyMotionNavigateWord = 0x101; + public const uint CmdEasyMotionNavigateExtend = 0x102; + public const uint CmdEasyMotionNavigateWordExtend = 0x103; - }; + }; } \ No newline at end of file From fc191ea3ee642404b839e159bbba0f264cfa89a3 Mon Sep 17 00:00:00 2001 From: Marias Marcell Date: Tue, 17 Oct 2017 23:26:01 +0200 Subject: [PATCH 4/5] Fixing a bug in search mode selection --- .../Implementation/Adornment/EasyMotionAdornmentController.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs index bdab7cb..345b368 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs @@ -112,7 +112,8 @@ private void AddAdornments() var toSearch = _easyMotionUtil.TargetChar.ToString(); var data = new FindData() { - SearchString = _easyMotionUtil.SearchMode == EasyMotionSearchMode.Char ? toSearch : @"\b" + toSearch, + SearchString = _easyMotionUtil.SearchMode == EasyMotionSearchMode.Char || _easyMotionUtil.SearchMode == EasyMotionSearchMode.CharExtend + ? toSearch : @"\b" + toSearch, TextSnapshotToSearch = snapshot, FindOptions = FindOptions.UseRegularExpressions }; From fe875fb19e5a3a41eacadd97a272a9acff394cc1 Mon Sep 17 00:00:00 2001 From: Marias Marcell Date: Thu, 19 Oct 2017 10:08:18 +0200 Subject: [PATCH 5/5] Handling invalid search characters in word mode --- EasyMotion/IEasyMotionUtil.cs | 2 ++ .../Adornment/EasyMotionAdornmentController.cs | 10 +++++++--- .../Implementation/EasyMotionUtil/EasyMotionUtil.cs | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/EasyMotion/IEasyMotionUtil.cs b/EasyMotion/IEasyMotionUtil.cs index 9a23d25..28e8a89 100644 --- a/EasyMotion/IEasyMotionUtil.cs +++ b/EasyMotion/IEasyMotionUtil.cs @@ -79,6 +79,8 @@ internal interface IEasyMotionUtil void ChangeToLookingForDecision(char target); void ChangeToLookingCharNotFound(); + + bool IsInWordMode { get; } } internal interface IEasyMotionUtilProvider diff --git a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs index 345b368..c483f58 100644 --- a/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs +++ b/EasyMotion/Implementation/Adornment/EasyMotionAdornmentController.cs @@ -109,13 +109,17 @@ private void AddAdornments() var snapshot = startPoint.Snapshot; int navigateIndex = 0; + if (_easyMotionUtil.IsInWordMode && !char.IsLetterOrDigit(_easyMotionUtil.TargetChar)) + { + _easyMotionUtil.ChangeToLookingCharNotFound(); + return; + } var toSearch = _easyMotionUtil.TargetChar.ToString(); var data = new FindData() { - SearchString = _easyMotionUtil.SearchMode == EasyMotionSearchMode.Char || _easyMotionUtil.SearchMode == EasyMotionSearchMode.CharExtend - ? toSearch : @"\b" + toSearch, + SearchString = _easyMotionUtil.IsInWordMode ? @"\b" + toSearch : toSearch, TextSnapshotToSearch = snapshot, - FindOptions = FindOptions.UseRegularExpressions + FindOptions = _easyMotionUtil.IsInWordMode ? FindOptions.UseRegularExpressions : FindOptions.None }; var startindex = startPoint.Position; diff --git a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs index cf13015..dd55031 100644 --- a/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs +++ b/EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs @@ -34,6 +34,8 @@ public ITextView TextView get { return _textView; } } + public bool IsInWordMode => SearchMode == EasyMotionSearchMode.Word || SearchMode == EasyMotionSearchMode.WordExtend; + public event EventHandler StateChanged; internal EasyMotionUtil(ITextView textView)