#region License // Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved. // This source code is made available under the terms of the GNU Lesser General Public License v3.0 // https://github.com/paulkohler/minisqlquery/blob/master/LICENSE #endregion using System; namespace MiniSqlQuery.Core { /// /// A simple text finding service. Currently supports forward only text matching. /// public class BasicTextFindService : ITextFindService { /// /// The services reference. /// private readonly IApplicationServices _services; /// /// Initializes a new instance of the class. Creates a new text find service. /// /// A reference to the application services. public BasicTextFindService(IApplicationServices applicationServices) { _services = applicationServices; } /// /// Looks for the next match depending on the settings in the . /// /// The text find request. /// An updated request with the relevent values adjusted (namely position). public FindTextRequest FindNext(FindTextRequest request) { if (request == null) { throw new ArgumentNullException("request"); } /* if (request.SearchUp) { // todo - I think its the TextProvider's job...? } else // search down. { int pos = request.TextProvider.FindString(request.SearchValue, request.Position, request.StringComparison); //pos = request.TextProvider.FindString(request); } */ int pos = request.TextProvider.FindString(request.SearchValue, request.Position, request.StringComparison); if (pos > -1) { // the editor will highlight the find request.Position = pos + request.SearchValue.Length; } else { // todo - notify, beep etc // reset to start of buffer. request.Position = 0; } return request; } } }