/// <summary> /// Gets the next valid match but fixes position with selected text's length /// </summary> public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List<SearchMatch> matches, Boolean forward, Boolean fixedPosition) { SearchMatch nearestMatch = matches[0]; Int32 currentPosition = sci.MBSafeCharPosition(sci.CurrentPos); if (fixedPosition) currentPosition -= sci.MBSafeTextLength(sci.SelText); for (Int32 i = 0; i < matches.Count; i++) { if (forward) { if (currentPosition > matches[matches.Count - 1].Index) { return matches[0]; } if (matches[i].Index >= currentPosition) { return matches[i]; } } else { if (sci.SelText.Length > 0 && currentPosition <= matches[0].Index + matches[0].Value.Length) { return matches[matches.Count - 1]; } if (currentPosition < matches[0].Index + matches[0].Value.Length) { return matches[matches.Count - 1]; } if (sci.SelText.Length == 0 && currentPosition == matches[i].Index + matches[i].Value.Length) { return matches[i]; } if (matches[i].Index > nearestMatch.Index && matches[i].Index + matches[i].Value.Length < currentPosition) { nearestMatch = matches[i]; } } } return nearestMatch; }
private static int SearchNextNewLineWithoutChar(ScintillaControl sender, int position, string text, ref char firstChar) { char c; int safe = sender.MBSafeCharPosition(position); int search = safe + text.Length; // int pos = 0; bool findNewLineBefore = false; do { c = sender.Text[search]; if(!char.IsWhiteSpace(c)) break; if (c == '\n' || c=='\r') findNewLineBefore = true; search++; } while (true); firstChar = c; if (findNewLineBefore) { return 1; } return 0; }
/// <summary> /// Gets a word from the specified position /// </summary> public static string GetWordFromPosition(ScintillaControl sci,int position, ref int start, ref int end) { try { //startPosition = sci.MBSafeCharPosition(sci.WordStartPosition(position, true)); //endPosition = sci.MBSafeCharPosition(sci.WordEndPosition(position, true)); //string keyword = sci.Text.Substring(startPosition, endPosition - startPosition); start = sci.WordStartPosition(position, true); end = sci.WordEndPosition(position, true); int startPosition = sci.MBSafeCharPosition(start); int endPosition = sci.MBSafeCharPosition(end); string keyword = sci.Text.Substring(startPosition, endPosition - startPosition); if (keyword.Length==0 || keyword.Equals(" ")) return null; //startPosition = sci.WordStartPosition(position, true); //endPosition = sci.WordEndPosition(position, true); return keyword.Trim(); } catch { return null; } }
public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List<SearchMatch> matches, int position) { SearchMatch nearestMatch = matches[0]; Int32 currentPosition = sci.MBSafeCharPosition(position); for (Int32 i = 0; i < matches.Count; i++) { if (currentPosition > matches[matches.Count - 1].Index) { return matches[0]; } if (matches[i].Index >= currentPosition) { return matches[i]; } } return nearestMatch; }