/// <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.EnsureVisibleEnforcePolicy(line); sci.SetSel(start, end); }
/// <summary> /// Moves the cursor to the previous marker /// </summary> public static void PreviousMarker(ScintillaControl sci, Int32 marker, Int32 line) { Int32 prev = 0; Int32 count = 0; Int32 lineMask = sci.MarkerGet(line); if ((lineMask & GetMarkerMask(marker)) != 0) { prev = sci.MarkerPrevious(line - 1, GetMarkerMask(marker)); if (prev != -1) { sci.EnsureVisibleEnforcePolicy(prev); sci.GotoLineIndent(prev); } else { count = sci.LineCount; prev = sci.MarkerPrevious(count, GetMarkerMask(marker)); if (prev != -1) { sci.EnsureVisibleEnforcePolicy(prev); sci.GotoLineIndent(prev); } } } else { prev = sci.MarkerPrevious(line, GetMarkerMask(marker)); if (prev != -1) { sci.EnsureVisibleEnforcePolicy(prev); sci.GotoLineIndent(prev); } else { count = sci.LineCount; prev = sci.MarkerPrevious(count, GetMarkerMask(marker)); if (prev != -1) { sci.EnsureVisibleEnforcePolicy(prev); sci.GotoLineIndent(prev); } } } }
/// <summary> /// Moves the cursor to the next marker /// </summary> public static void NextMarker(ScintillaControl sci, Int32 marker, Int32 line) { Int32 next = 0; Int32 lineMask = sci.MarkerGet(line); if ((lineMask & GetMarkerMask(marker)) != 0) { next = sci.MarkerNext(line + 1, GetMarkerMask(marker)); if (next != -1) { sci.EnsureVisibleEnforcePolicy(next); sci.GotoLineIndent(next); } else { next = sci.MarkerNext(0, GetMarkerMask(marker)); if (next != -1) { sci.EnsureVisibleEnforcePolicy(next); sci.GotoLineIndent(next); } } } else { next = sci.MarkerNext(line, GetMarkerMask(marker)); if (next != -1) { sci.EnsureVisibleEnforcePolicy(next); sci.GotoLineIndent(next); } else { next = sci.MarkerNext(0, GetMarkerMask(marker)); if (next != -1) { sci.EnsureVisibleEnforcePolicy(next); sci.GotoLineIndent(next); } } } }
/// <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.EnsureVisibleEnforcePolicy(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(); } }
void delayOpen_Tick(object sender, EventArgs e) { delayOpen.Stop(); if (fileToOpen != null) { if (File.Exists(fileToOpen)) { PluginBase.MainForm.OpenEditableDocument(fileToOpen, false); if (PluginBase.MainForm.CurrentDocument.IsEditable && PluginBase.MainForm.CurrentDocument.FileName.Equals(fileToOpen, StringComparison.OrdinalIgnoreCase)) { ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; int pos = sci.PositionFromLine(lineToOpen); sci.SetSel(pos, pos); sci.EnsureVisibleEnforcePolicy(lineToOpen); } } fileToOpen = null; } }
private bool FindAndHighlight(bool dirn, int min, int max) { TextView view = mManager.ActiveView as TextView; ScintillaControl editControl = view.ScintillaControl; bool matchCase = checkBoxMatchCase.Checked; bool matchWholeWord = checkBoxMatchWholeWord.Checked; bool useRegex = checkBoxUseRegularExpressions.Checked; string findString = comboBoxFindWhat.Text; int flags = 0; if (matchCase) { flags = flags | (int)Scintilla.Enums.FindOption.MatchCase; } if (matchWholeWord) { flags = flags | (int)Scintilla.Enums.FindOption.WholeWord; } if (useRegex) { flags = flags | (int)Scintilla.Enums.FindOption.RegularExpression; } int startPos, endPos; int prevStartPos = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionStart : editControl.SelectionEnd; int prevEndPos = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionEnd : editControl.SelectionStart; if (dirn) { editControl.CurrentPos = editControl.SelectionStart = editControl.SelectionEnd = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionEnd : editControl.SelectionStart; editControl.SearchAnchor(); startPos = editControl.SearchNext(flags, findString); } else { editControl.CurrentPos = editControl.SelectionStart = editControl.SelectionEnd = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionStart : editControl.SelectionEnd; editControl.SearchAnchor(); startPos = editControl.SearchPrevious(flags, findString); } bool foundMatch = (startPos >= 0); if (foundMatch) { startPos = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionStart : editControl.SelectionEnd; endPos = (editControl.SelectionStart < editControl.SelectionEnd) ? editControl.SelectionEnd : editControl.SelectionStart; if (startPos >= min && endPos <= max) { int lineIndex = editControl.LineFromPosition(editControl.CurrentPos); editControl.EnsureVisibleEnforcePolicy(lineIndex); editControl.ScrollCaret(); editControl.CurrentPos = endPos; editControl.SelectionStart = startPos; editControl.SelectionEnd = endPos; } else { foundMatch = false; editControl.CurrentPos = prevEndPos; editControl.SelectionStart = prevStartPos; editControl.SelectionEnd = prevEndPos; } } return(foundMatch); }
/// <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.EnsureVisibleEnforcePolicy(line); }