Ejemplo n.º 1
0
/* TextEditor::findPrev
 * Finds the previous occurrence of the [find] after the caret
 * position, selects it and scrolls to it if needed. Returns false
 * if the [find] was invalid or no match was found, true otherwise
 *******************************************************************/
bool TextEditor::findPrev(string find, int flags)
{
	// Check search string
	if (find.IsEmpty())
		return false;

	// Get current selection
	int sel_start = GetSelectionStart();
	int sel_end = GetSelectionEnd();

	// Search back from the start of the current selection
	SetSelection(sel_start, sel_start);
	SearchAnchor();
	int found = SearchPrev(flags, find);
	if (found < 0)
	{
		// Not found, loop back to end
		SetSelection(GetTextLength() - 1, GetTextLength() - 1);
		SearchAnchor();
		found = SearchPrev(flags, find);
		if (found < 0)
		{
			// No match found in entire text, reset selection
			SetSelection(sel_start, sel_end);
			return false;
		}
	}

	// Set caret to the end of the matching text
	// (it defaults to the start for some dumb reason)
	// and scroll to the selection
	SetSelection(found, found + find.length());
	EnsureCaretVisible();

	return true;
}
Ejemplo n.º 2
0
bool Edit::FindText(int &found_start, int &found_end, bool find_next)
{
  const int flags = m_FindData.GetFlags();
  const bool find_down = (flags & wxFR_DOWN) ? true : false;
  const wxString find_string = m_FindData.GetFindString();
  found_start = found_end = -1;

  if (find_next) {
    GotoPos(find_down ? GetCurrentPos() : GetCurrentPos() - find_string.size());
  }
  SearchAnchor();

  // search up/down
  found_start = find_down ? SearchNext(flags, find_string) : SearchPrev(flags, find_string);

  // found
  if (found_start > -1) {
    found_end = found_start + find_string.size();
    GotoPos(found_start);
    return true;
  }
  
  return false;
}