/// <summary> /// Selects a search match /// </summary> public static void SelectMatch(ScintillaControl sci, SearchMatch match) { Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length Int32 line = sci.LineFromPosition(start); sci.EnsureVisible(line); sci.SetSel(start, end); }
/// <summary> /// Bookmarks a search match /// </summary> public static void BookmarkMatches(ScintillaControl sci, List<SearchMatch> matches) { for (Int32 i = 0; i < matches.Count; i++) { Int32 line = matches[i].Line - 1; sci.EnsureVisible(line); sci.MarkerAdd(line, 0); } }
/// <summary> /// Replaces only the matches in the current sci control /// </summary> public static void ReplaceMatches(IList<SearchMatch> matches, ScintillaControl sci, String replacement, String src) { if (sci == null || matches == null || matches.Count == 0) return; sci.BeginUndoAction(); try { for (Int32 i = 0; i < matches.Count; i++) { SelectMatch(sci, matches[i]); FRSearch.PadIndexes((List<SearchMatch>)matches, i, matches[i].Value, replacement); sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(matches[i].Index))); sci.ReplaceSel(replacement); } } finally { sci.EndUndoAction(); } }
/// <summary> /// Applies the state object to a scintilla control /// </summary> private static void ApplyStateObject(ScintillaControl sci, StateObject so, Boolean restorePosition) { if (so.LineCount != sci.LineCount) return; sci.Refresh(); // Update the scintilla control state for (Int32 i = 0; i < so.FoldedLines.Count; i++) { Int32 foldedLine = so.FoldedLines[i]; sci.ToggleFold(foldedLine); } if (so.BookmarkedLines != null) { for (Int32 i = 0; i < so.BookmarkedLines.Count; i++) { Int32 bookmarkedLine = so.BookmarkedLines[i]; sci.MarkerAdd(bookmarkedLine, 0); } sci.Refresh(); // Update again } if (restorePosition) { sci.FirstVisibleLine = so.LineScroll; Int32 line = sci.LineFromPosition(so.Position); sci.SetSel(so.Position, so.Position); sci.EnsureVisible(line); } }
/// <summary> /// Move the document position /// </summary> private void MoveToPosition(ScintillaControl sci, Int32 position) { try { position = sci.MBSafePosition(position); // scintilla indexes are in 8bits Int32 line = sci.LineFromPosition(position); sci.EnsureVisible(line); sci.GotoPos(position); sci.SetSel(position, sci.LineEndPosition(line)); sci.Focus(); } catch { String message = TextHelper.GetString("Info.InvalidItem"); ErrorManager.ShowInfo(message); this.RemoveInvalidItems(); this.RefreshProject(); } }
/// <summary> /// Goes to the match and ensures that correct fold is opened /// </summary> private void MBSafeSetSelAndFocus(ScintillaControl sci, Int32 line, Int32 startPosition, Int32 endPosition) { sci.MBSafeSetSel(startPosition, endPosition); sci.EnsureVisible(line); }
/// <summary> /// Move the document position /// </summary> /// <param name="sci"></param> /// <param name="position"></param> private void MoveToPosition( ScintillaControl sci, int position ) { int line = sci.LineFromPosition(position); sci.EnsureVisible( line ); sci.GotoPos(position); sci.SetSel(position, sci.LineEndPosition(line)); sci.Focus(); }