Ejemplo n.º 1
0
        ///<summary></summary>
        private List <MatchOD> GetWords()
        {
            List <MatchOD>  wordList = new List <MatchOD>();
            MatchCollection mc       = Regex.Matches(Text, @"(\S+)");   //use Regex.Matches because our matches include the index within our text for underlining

            foreach (Match m in mc)
            {
                Group g = m.Groups[0];              //Group 0 is the entire match
                if (g.Value.Length < 2)             //only allow 'words' that are at least two chars long, 1 char 'words' are assumed spelled correctly
                {
                    continue;
                }
                MatchOD word = new MatchOD();
                word.StartIndex = g.Index;              //this index is the index within Text of the first char of this word (match)
                word.Value      = g.Value;
                //loop through starting at the beginning of word looking for first letter or digit
                while (word.Value.Length > 1 && !Char.IsLetterOrDigit(word.Value[0]))
                {
                    word.Value = word.Value.Substring(1);
                    word.StartIndex++;
                }
                //loop through starting at the last char looking for the last letter or digit
                while (word.Value.Length > 1 && !Char.IsLetterOrDigit(word.Value[word.Value.Length - 1]))
                {
                    word.Value = word.Value.Substring(0, word.Value.Length - 1);
                }
                if (word.Value.Length > 1)
                {
                    if (Regex.IsMatch(word.Value, @"[^a-zA-Z\'\-]"))
                    {
                        continue;
                    }
                    wordList.Add(word);
                }
            }
            return(wordList);
        }
Ejemplo n.º 2
0
		///<summary></summary>
		private List<MatchOD> GetWords() {
			List<MatchOD> wordList=new List<MatchOD>();
			MatchCollection mc=Regex.Matches(Text,@"(\S+)");//use Regex.Matches because our matches include the index within our text for underlining
			foreach(Match m in mc) {
				Group g=m.Groups[0];//Group 0 is the entire match
				if(g.Value.Length<2) {//only allow 'words' that are at least two chars long, 1 char 'words' are assumed spelled correctly
					continue;
				}
				MatchOD word=new MatchOD();
				word.StartIndex=g.Index;//this index is the index within Text of the first char of this word (match)
				word.Value=g.Value;
				//loop through starting at the beginning of word looking for first letter or digit
				while(word.Value.Length>1 && !Char.IsLetterOrDigit(word.Value[0])) {
					word.Value=word.Value.Substring(1);
					word.StartIndex++;
				}
				//loop through starting at the last char looking for the last letter or digit
				while(word.Value.Length>1 && !Char.IsLetterOrDigit(word.Value[word.Value.Length-1])) {
					word.Value=word.Value.Substring(0,word.Value.Length-1);
				}
				if(word.Value.Length>1) {
					if(Regex.IsMatch(word.Value,@"[^a-zA-Z\'\-]")) {
						continue;
					}
					wordList.Add(word);
				}
			}
			return wordList;
		}
Ejemplo n.º 3
0
        ///<summary>Determines whether the right click was on a misspelled word.  Also sets the start and end index of chars to be replaced in text.</summary>
        private bool IsOnMisspelled(Point PositionOfClick)
        {
            int   charIndex    = this.GetCharIndexFromPosition(PositionOfClick);
            Point charLocation = this.GetPositionFromCharIndex(charIndex);

            if (PositionOfClick.Y < charLocation.Y - 2 || PositionOfClick.Y > charLocation.Y + this.FontHeight + 2)   //this is the closest char but they were not very close when they right clicked
            {
                return(false);
            }
            char c = this.GetCharFromPosition(PositionOfClick);

            if (c == '\n')           //if closest char is a new line char, then assume not on a misspelled word
            {
                return(false);
            }
            List <MatchOD> words = GetWords();

            if (words.Count == 0)
            {
                return(false);
            }
            int ind = 0;

            #region Binary search to find first word in visible area
            int minIndex = 0;
            int maxIndex = words.Count - 1;
            ind = maxIndex;
            while (maxIndex > minIndex)
            {
                if (this.GetPositionFromCharIndex(words[ind].StartIndex).Y < 0)               //words[ind] is above the visible area, so make ind our new minimum index
                {
                    minIndex = ind;
                }
                else if (this.GetPositionFromCharIndex(words[ind].StartIndex).Y > this.Height)               //words[ind] is beyond the visible area, so make ind our new maximum index
                {
                    maxIndex = ind;
                }
                else
                {
                    break;
                }
                ind = maxIndex - ((maxIndex - minIndex) / 2);       //set ind to be the halfway point between max and min
                if (ind == maxIndex || ind == minIndex)             //this will occur if there is no word in the visible area, break out of loop
                {
                    break;
                }
            }
            #endregion
            if (this.GetPositionFromCharIndex(words[ind].StartIndex).Y > 0 && this.GetPositionFromCharIndex(words[ind].StartIndex).Y <= this.Height)         //if words[ind] is in visible area
            {
                while (ind > 0 && this.GetPositionFromCharIndex(words[ind - 1].StartIndex).Y > 0)
                {
                    ind--;                    //backup to first visible word
                }
            }
            for (int i = ind; i < words.Count; i++)
            {
                if (this.GetPositionFromCharIndex(words[i].StartIndex).Y > this.Height)
                {
                    ReplWord = null;
                    break;
                }
                if (charIndex >= words[i].StartIndex && charIndex <= (words[i].StartIndex + words[i].Value.Length - 1))
                {
                    ReplWord = words[i];
                    break;
                }
            }
            if (ReplWord == null)
            {
                return(false);
            }
            if (ListIncorrect.Contains(ReplWord.Value))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
		///<summary>Determines whether the right click was on a misspelled word.  Also sets the start and end index of chars to be replaced in text.</summary>
		private bool IsOnMisspelled(Point PositionOfClick) {
			int charIndex=this.GetCharIndexFromPosition(PositionOfClick);
			Point charLocation=this.GetPositionFromCharIndex(charIndex);
			if(PositionOfClick.Y<charLocation.Y-2 || PositionOfClick.Y>charLocation.Y+this.FontHeight+2) {//this is the closest char but they were not very close when they right clicked
				return false;
			}
			char c=this.GetCharFromPosition(PositionOfClick);
			if(c=='\n') {//if closest char is a new line char, then assume not on a misspelled word
				return false;
			}
			List<MatchOD> words=GetWords();
			if(words.Count==0) {
				return false;
			}
			int ind=0;
			#region Binary search to find first word in visible area
			int minIndex=0;
			int maxIndex=words.Count-1;
			ind=maxIndex;
			while(maxIndex > minIndex) {
				if(this.GetPositionFromCharIndex(words[ind].StartIndex).Y<0) {//words[ind] is above the visible area, so make ind our new minimum index
					minIndex=ind;
				}
				else if(this.GetPositionFromCharIndex(words[ind].StartIndex).Y>this.Height) {//words[ind] is beyond the visible area, so make ind our new maximum index
					maxIndex=ind;
				}
				else {
					break;
				}
				ind=maxIndex-((maxIndex-minIndex)/2);//set ind to be the halfway point between max and min
				if(ind==maxIndex || ind==minIndex) {//this will occur if there is no word in the visible area, break out of loop
					break;
				}
			}
			#endregion
			if(this.GetPositionFromCharIndex(words[ind].StartIndex).Y>0 && this.GetPositionFromCharIndex(words[ind].StartIndex).Y<=this.Height) {//if words[ind] is in visible area
				while(ind>0 && this.GetPositionFromCharIndex(words[ind-1].StartIndex).Y>0) {
					ind--;//backup to first visible word
				}
			}
			for(int i=ind;i<words.Count;i++) {
				if(this.GetPositionFromCharIndex(words[i].StartIndex).Y>this.Height) {
					ReplWord=null;
					break;
				}
				if(charIndex>=words[i].StartIndex && charIndex<=(words[i].StartIndex+words[i].Value.Length-1)) {
					ReplWord=words[i];
					break;
				}
			}
			if(ReplWord==null) {
				return false;
			}
			if(ListIncorrect.Contains(ReplWord.Value)) {
				return true;
			}
			return false;
		}