Exemplo n.º 1
0
        protected override void Run(object data)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            var editor = doc.Editor;

            if (editor == null)
            {
                return;
            }

            string abbrevWord;
            int    offset;
            int    startOffset;

            if (lastView == editor && editor.CaretOffset == lastTriggerOffset)
            {
                abbrevWord = lastAbbrev;
                offset     = lastStartOffset;
            }
            else
            {
                abbrevWord    = GetWordBeforeCaret(editor);
                lastAbbrev    = abbrevWord;
                offset        = editor.CaretOffset - abbrevWord.Length - 1;
                lastInsertPos = lastTriggerOffset = offset + 1;
                foundWords.Clear();
                foundWords.Add(abbrevWord);
                curState = AbbrevState.SearchBackward;
            }

            lastView = editor;
            switch (curState)
            {
            case AbbrevState.SearchBackward:
                while (offset > 0)
                {
                    if (IsMatchAt(editor, offset, abbrevWord))
                    {
                        int    endOffset = SearchEndPos(offset, editor);
                        string curWord   = editor.GetTextBetween(offset, endOffset);
                        if (foundWords.Contains(curWord))
                        {
                            offset--;
                            continue;
                        }
                        foundWords.Add(curWord);
                        ReplaceWord(editor, curWord);
                        lastStartOffset = offset - 1;
                        return;
                    }
                    offset--;
                }
                offset   = editor.CaretOffset;
                curState = AbbrevState.SearchForward;
                goto case AbbrevState.SearchForward;

            case AbbrevState.SearchForward:
                while (offset < editor.Length)
                {
                    if (IsMatchAt(editor, offset, abbrevWord))
                    {
                        int    endOffset = SearchEndPos(offset, editor);
                        string curWord   = editor.GetTextBetween(offset, endOffset);
                        if (foundWords.Contains(curWord))
                        {
                            offset++;
                            continue;
                        }
                        foundWords.Add(curWord);
                        ReplaceWord(editor, curWord);
                        lastStartOffset = offset + 1;
                        return;
                    }
                    offset++;
                }
                curState = AbbrevState.SearchOtherBuffers;
                goto case AbbrevState.SearchOtherBuffers;

            case AbbrevState.SearchOtherBuffers:
                foreach (Document curDoc in IdeApp.Workbench.Documents)
                {
                    var otherView = curDoc.GetContent <TextEditor> ();
                    if (curDoc == doc || otherView == null)
                    {
                        continue;
                    }
                    for (int i = 0; i < otherView.Length; i++)
                    {
                        if (IsMatchAt(otherView, i, abbrevWord))
                        {
                            int    endOffset = SearchEndPos(i, otherView);
                            string curWord   = otherView.GetTextBetween(i, endOffset);
                            if (foundWords.Contains(curWord))
                            {
                                continue;
                            }
                            foundWords.Add(curWord);
                        }
                    }
                }
                curState = AbbrevState.CycleThroughFoundWords;
                goto case AbbrevState.CycleThroughFoundWords;

            case AbbrevState.CycleThroughFoundWords:
                int index = foundWords.IndexOf(editor.GetTextAt(lastInsertPos, editor.CaretOffset - lastInsertPos));
                if (index < 0)
                {
                    break;
                }
                startOffset = offset;
                offset      = startOffset + foundWords[index].Length;
                index       = (index + foundWords.Count + 1) % foundWords.Count;
                ReplaceWord(editor, foundWords[index]);
                break;
            }
        }
Exemplo n.º 2
0
		protected override void Run (object data)
		{
			MonoDevelop.Ide.Gui.Document doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null)
				return;
			SourceEditorView view = IdeApp.Workbench.ActiveDocument.GetContent<SourceEditorView> ();
			if (view == null)
				return;
			
			string abbrevWord;
			int offset;
			int startOffset;
			
			if (lastView == view && view.TextEditor.Caret.Offset == lastTriggerOffset) {
				abbrevWord = lastAbbrev;
				offset = lastStartOffset;
			} else {
				abbrevWord = GetWordBeforeCaret (view.TextEditor);
				lastAbbrev = abbrevWord;
				offset = view.TextEditor.Caret.Offset - abbrevWord.Length - 1;
				lastInsertPos = lastTriggerOffset = offset + 1;
				foundWords.Clear ();
				foundWords.Add (abbrevWord);
				curState = AbbrevState.SearchBackward;
			}
			
			lastView = view;
			switch (curState) {
			case AbbrevState.SearchBackward:
				while (offset > 0) {
					if (IsMatchAt (view, offset, abbrevWord)) {
						int endOffset = SearchEndPos (offset, view);
						string curWord = view.TextEditor.Document.GetTextBetween (offset, endOffset);
						if (foundWords.Contains (curWord)) {
							offset--;
							continue;
						}
						foundWords.Add (curWord);
						ReplaceWord (view, curWord);
						lastStartOffset = offset - 1;
						return;
					}
					offset--;
				}
				offset = view.TextEditor.Caret.Offset;
				curState = AbbrevState.SearchForward;
				goto case AbbrevState.SearchForward;
			case AbbrevState.SearchForward:
				while (offset < view.TextEditor.Document.TextLength) {
					if (IsMatchAt (view, offset, abbrevWord)) {
						int endOffset = SearchEndPos (offset, view);
						string curWord = view.TextEditor.Document.GetTextBetween (offset, endOffset);
						if (foundWords.Contains (curWord)) {
							offset++;
							continue;
						}
						foundWords.Add (curWord);
						ReplaceWord (view, curWord);
						lastStartOffset = offset + 1;
						return;
					}
					offset++;
				}
				curState = AbbrevState.SearchOtherBuffers;
				goto case AbbrevState.SearchOtherBuffers;
			case AbbrevState.SearchOtherBuffers:
				foreach (Document curDoc in IdeApp.Workbench.Documents) {
					SourceEditorView otherView = curDoc.GetContent<SourceEditorView> ();
					if (curDoc == doc || otherView == null || otherView.Document == null)
						continue;
					for (int i = 0; i < otherView.Document.TextLength; i++) {
						if (IsMatchAt (otherView, i, abbrevWord)) {
							int endOffset = SearchEndPos (i, otherView);
							string curWord = otherView.TextEditor.Document.GetTextBetween (i, endOffset);
							if (foundWords.Contains (curWord))
								continue;
							foundWords.Add (curWord);
						}
					}
				}
				curState = AbbrevState.CycleThroughFoundWords;
				goto case AbbrevState.CycleThroughFoundWords;
			case AbbrevState.CycleThroughFoundWords:
				int index = foundWords.IndexOf (view.TextEditor.Document.GetTextAt (lastInsertPos, view.TextEditor.Caret.Offset - lastInsertPos));
				if (index < 0)
					break;
				startOffset = offset;
				offset = startOffset + foundWords[index].Length;
				index = (index + foundWords.Count + 1) % foundWords.Count;
				ReplaceWord (view, foundWords[index]);
				break;
			}
		}
		protected override void Run (object data)
		{
			MonoDevelop.Ide.Gui.Document doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null)
				return;
			SourceEditorView view = IdeApp.Workbench.ActiveDocument.GetContent<SourceEditorView> ();
			if (view == null)
				return;
			
			string abbrevWord;
			int offset;
			int startOffset;
			
			if (lastView == view && view.TextEditor.Caret.Offset == lastTriggerOffset) {
				abbrevWord = lastAbbrev;
				offset = lastStartOffset;
			} else {
				abbrevWord = GetWordBeforeCaret (view.TextEditor);
				lastAbbrev = abbrevWord;
				offset = view.TextEditor.Caret.Offset - abbrevWord.Length - 1;
				lastInsertPos = lastTriggerOffset = offset + 1;
				foundWords.Clear ();
				foundWords.Add (abbrevWord);
				curState = AbbrevState.SearchBackward;
			}
			
			lastView = view;
			switch (curState) {
			case AbbrevState.SearchBackward:
				while (offset > 0) {
					if (IsMatchAt (view, offset, abbrevWord)) {
						int endOffset = SearchEndPos (offset, view);
						string curWord = view.TextEditor.Document.GetTextBetween (offset, endOffset);
						if (foundWords.Contains (curWord)) {
							offset--;
							continue;
						}
						foundWords.Add (curWord);
						ReplaceWord (view, curWord);
						lastStartOffset = offset - 1;
						return;
					}
					offset--;
				}
				offset = view.TextEditor.Caret.Offset;
				curState = AbbrevState.SearchForward;
				goto case AbbrevState.SearchForward;
			case AbbrevState.SearchForward:
				while (offset < view.TextEditor.Document.Length) {
					if (IsMatchAt (view, offset, abbrevWord)) {
						int endOffset = SearchEndPos (offset, view);
						string curWord = view.TextEditor.Document.GetTextBetween (offset, endOffset);
						if (foundWords.Contains (curWord)) {
							offset++;
							continue;
						}
						foundWords.Add (curWord);
						ReplaceWord (view, curWord);
						lastStartOffset = offset + 1;
						return;
					}
					offset++;
				}
				curState = AbbrevState.SearchOtherBuffers;
				goto case AbbrevState.SearchOtherBuffers;
			case AbbrevState.SearchOtherBuffers:
				foreach (Document curDoc in IdeApp.Workbench.Documents.Where (d => d != doc)) {
					SourceEditorView otherView = curDoc.GetContent<SourceEditorView> ();
					if (otherView == null)
						continue;
					for (int i = 0; i < otherView.Document.Length; i++) {
						if (IsMatchAt (otherView, i, abbrevWord)) {
							int endOffset = SearchEndPos (i, otherView);
							string curWord = otherView.TextEditor.Document.GetTextBetween (i, endOffset);
							if (foundWords.Contains (curWord))
								continue;
							foundWords.Add (curWord);
						}
					}
				}
				curState = AbbrevState.CycleThroughFoundWords;
				goto case AbbrevState.CycleThroughFoundWords;
			case AbbrevState.CycleThroughFoundWords:
				int index = foundWords.IndexOf (view.TextEditor.Document.GetTextAt (lastInsertPos, view.TextEditor.Caret.Offset - lastInsertPos));
				if (index < 0)
					break;
				startOffset = offset;
				offset = startOffset + foundWords[index].Length;
				index = (index + foundWords.Count + 1) % foundWords.Count;
				ReplaceWord (view, foundWords[index]);
				break;
			}
		}