// change current word into 'ChangeTo' value void _btnChange_Click(object sender, RoutedEventArgs e) { if (_txtError.Text != _originalText) { // replace whole sentence in editor _editor.Select(_sentence.Start, _sentence.Length); _editor.SelectedText = _txtError.Text; // re-check starting from the sentence start _errors = _spell.CheckText(_editor.Text, _sentence.Start); } else { // save starting point to continue checking from here int start = CurrentError.Start; // get replacement text string replacement = _textChangeTo; if (string.IsNullOrEmpty(replacement)) { // if replacement is empty, expand over spaces and commas CharRange delete = CharRange.ExpandOverWhitespace(_editor.Text, CurrentError); _editor.Select(delete.Start, delete.Text.Length); replacement = string.Empty; } // replace word in text and re-check _editor.SelectedText = replacement; _errors = _spell.CheckText(_editor.Text, start); } // update index ErrorIndex = 0; }
// change current word into 'ChangeTo' value private void _btnChange_Click(object sender, EventArgs e) { // save starting point to continue checking from here int start = CurrentError.Start; // get replacement text string replacement = _txtChangeTo.Text; if (replacement.Length == 0) { // if replacement is empty, expand over spaces and commas CharRange delete = CharRange.ExpandOverWhitespace(_editor.Text, CurrentError); _editor.Select(delete.Start, delete.Text.Length); } // replace word in text and re-check _editor.SelectedText = replacement; _errors = _spell.CheckText(_editor.Text, start); // update index ErrorIndex = 0; }
// change current word into 'ChangeTo' value private void _btnChange_Click(object sender, EventArgs e) { // save starting point to continue checking from here int start = CurrentError.Start; // if the user typed into the text error box, handle that CharRange replacement = null; if (ReplacementTextChanged && _listSuggestions.Enabled == false) { // get part of the text that replaced the actual error within the sentence replacement = GetReplacement(); if (replacement != null && replacement.Text.Length > 0) { // warn if replacement is bad if (_spell.CheckText(replacement.Text).Count > 0) { string msg = "You have chosen a word that is not in the dictionary.\r\n" + "Do you want to use this word and continue checking?"; DialogResult dr = MessageBox.Show(this, msg, "Spelling", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.No) { return; } } // honor ChangeAll button if (sender.Equals(_btnChangeAll)) { _changeAll[CurrentError.Text] = replacement.Text; } } // replace whole sentence in text _editor.Select(_sentence.Start, _sentence.Length); _editor.SelectedText = _txtError.Text; // resume checking from sentence start start = _sentence.Start; } else { // no changes in text, use Suggestion/ChangeAll value stored in _txtChangeTo string changeTo = _textChangeTo; if (changeTo.Length == 0) { // if replacement is empty, expand over spaces and commas CharRange delete = CharRange.ExpandOverWhitespace(_editor.Text, CurrentError); _editor.Select(delete.Start, delete.Text.Length); } // honor ChangeAll button if (sender.Equals(_btnChangeAll)) { _changeAll[CurrentError.Text] = changeTo; } // replace word in text _editor.SelectedText = changeTo; _errors = _spell.CheckText(_editor.Text); } // re-check _errors = _spell.CheckText(_editor.Text); _errorIndex = -1; for (int index = 0; index < _errors.Count; index++) { if (_errors[index].Start >= start) { if (replacement == null || replacement.Text != _errors[index].Text) { _errorIndex = index; break; } } } // show the current error UpdateCurrentError(); }