Skip to content

Commit

Permalink
Handling invalid search characters in word mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mariasm75 committed Oct 19, 2017
1 parent fc191ea commit fe875fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions EasyMotion/IEasyMotionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ internal interface IEasyMotionUtil
void ChangeToLookingForDecision(char target);

void ChangeToLookingCharNotFound();

bool IsInWordMode { get; }
}

internal interface IEasyMotionUtilProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions EasyMotion/Implementation/EasyMotionUtil/EasyMotionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fe875fb

Please sign in to comment.