Exemplo n.º 1
0
        static string GetCurrentWordForMethods(CompletionListWindow window, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
        {
            int partialWordLength = window.PartialWord != null ? window.PartialWord.Length : 0;
            int replaceLength;

            if (descriptor.SpecialKey == SpecialKey.Return || descriptor.SpecialKey == SpecialKey.Tab)
            {
                replaceLength = window.CodeCompletionContext.TriggerWordLength + partialWordLength - window.InitialWordLength;
            }
            else
            {
                replaceLength = partialWordLength;
            }
            int endOffset = Math.Min(window.StartOffset + replaceLength, window.CompletionWidget.TextLength);

            if (descriptor.KeyChar == '(' && DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket)
            {
                endOffset++;
                if (DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket)
                {
                    endOffset++;
                }
            }
            var result = window.CompletionWidget.GetText(window.StartOffset, endOffset);

            return(result);
        }
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            // generic mode escape handler
            if (
                (descriptor.ModifierKeys == 0 && descriptor.SpecialKey == SpecialKey.Escape) ||
                (descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == '[') ||
                (descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == 'c'))
            {
                _currentMode.Deactivate();
                _currentMode = _requestedMode = _normalMode;
                _currentMode.Activate();
                return false;
            }

            var pass = _currentMode.KeyPress (descriptor);

            var newMode = _currentMode.RequestedMode;
            if (newMode == ViMode.Normal)
                _requestedMode = _normalMode;
            else if (newMode == ViMode.Insert)
                _requestedMode = _insertMode;
            else if (newMode == ViMode.Visual)
                _requestedMode = _visualMode;

            if (_requestedMode != _currentMode)
            {
                _currentMode.RequestedMode = ViMode.None;
                _currentMode.Deactivate();
                _requestedMode.Activate();
                _currentMode = _requestedMode;
            }

            return pass && base.KeyPress(descriptor);
        }
		// Called when a key is pressed in the editor.
		// Returns false if the key press has to continue normal processing.
		internal static bool ProcessKeyEvent (CompletionTextEditorExtension ext, ICompletionWidget widget, KeyDescriptor descriptor)
		{
			if (methods.Count == 0)
				return false;

			MethodData cmd = methods [methods.Count - 1];

			if (descriptor.SpecialKey == SpecialKey.Down) {
				if (cmd.MethodProvider.Count <= 1)
					return false;
				if (cmd.CurrentOverload < cmd.MethodProvider.Count - 1)
					cmd.CurrentOverload ++;
				else
					cmd.CurrentOverload = 0;
				window.ChangeOverload ();
				UpdateWindow (ext, widget);
				return true;
			} else if (descriptor.SpecialKey == SpecialKey.Up) {
				if (cmd.MethodProvider.Count <= 1)
					return false;
				if (cmd.CurrentOverload > 0)
					cmd.CurrentOverload --;
				else
					cmd.CurrentOverload = cmd.MethodProvider.Count - 1;
				window.ChangeOverload ();
				UpdateWindow (ext, widget);
				return true;
			}
			else if (descriptor.SpecialKey == SpecialKey.Escape) {
				HideWindow (ext, widget);
				return true;
			}
			return false;
		}
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			if (descriptor.KeyChar != '/')
				return base.KeyPress (descriptor);
			
			var line = Editor.GetLine (Editor.CaretLine);
			string text = Editor.GetTextAt (line.Offset, line.Length);
			
			if (!text.EndsWith ("//", StringComparison.Ordinal))
				return base.KeyPress (descriptor);

			// check if there is doc comment above or below.
			var l = line.PreviousLine;
			while (l != null && l.Length == 0)
				l = l.PreviousLine;
			if (l != null && Editor.GetTextAt (l).TrimStart ().StartsWith ("///", StringComparison.Ordinal))
				return base.KeyPress (descriptor);

			l = line.NextLine;
			while (l != null && l.Length == 0)
				l = l.NextLine;
			if (l != null && Editor.GetTextAt (l).TrimStart ().StartsWith ("///", StringComparison.Ordinal))
				return base.KeyPress (descriptor);

			var memberTask = GetMemberToDocument ();
			if (!memberTask.Wait (250) || memberTask.Result == null)
				return base.KeyPress (descriptor);
			var member = memberTask.Result;
			
			string documentation = GenerateDocumentation (member, Editor.GetLineIndent (line));
			if (string.IsNullOrEmpty (documentation))
				return base.KeyPress (descriptor);
			
			string documentationEmpty = GenerateEmptyDocumentation (member, Editor.GetLineIndent (line));
			
			int offset = Editor.CaretOffset;
			
			int insertedLength;
			
			// Insert key (3rd undo step)
			Editor.InsertText (offset, "/");
			using (var undo = Editor.OpenUndoGroup ()) {
				documentationEmpty = Editor.FormatString (offset, documentationEmpty); 
				insertedLength = documentationEmpty.Length;
				Editor.ReplaceText (offset, 1, documentationEmpty);
				// important to set the caret position here for the undo step
				Editor.CaretOffset = offset + insertedLength;
			}
			
			using (var undo = Editor.OpenUndoGroup ()) {
				documentation = Editor.FormatString (offset, documentation); 
				Editor.ReplaceText (offset, insertedLength, documentation);
				insertedLength = documentation.Length;
				if (SelectSummary (offset, insertedLength, documentation) == false)
					Editor.CaretOffset = offset + insertedLength;
			}
			return false;
		}
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			var editor = factory.Ext.Editor;
			var offset = window.CodeCompletionContext.TriggerOffset;
			using (var undo = editor.OpenUndoGroup ()) {
				base.InsertCompletionText (window, ref ka, descriptor);
				var span = nodeToCast.Span;
				var type = SafeMinimalDisplayString (targetType, semanticModel, nodeToCast.SpanStart, Ambience.LabelFormat);
				editor.ReplaceText (span.Start, span.Length, "((" + type + ")" + nodeToCast + ")");
			}
		}
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			var result = base.KeyPress (descriptor);

			if (DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket && !Editor.IsSomethingSelected) {
				var handler = allHandlers.FirstOrDefault(h => h.CanHandle (Editor));
				if (handler != null && handler.Handle (Editor, DocumentContext, descriptor))
					return false;
			}
			return result;
		}
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			var buf = window.CompletionWidget;
			if (buf != null) {
				//completion context gets nulled from window as soon as we alter the buffer
				var codeCompletionContext = window.CodeCompletionContext;

				buf.Replace (buf.CaretOffset, 0, element);
					
				// Move caret into the middle of the tags
				buf.CaretOffset = codeCompletionContext.TriggerOffset + cursorOffset;
			}
		}
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			var result = base.KeyPress (descriptor);

			if (descriptor.SpecialKey == SpecialKey.Return) {
				if (Editor.Options.IndentStyle == MonoDevelop.Ide.Editor.IndentStyle.Virtual) {
					if (Editor.GetLine (Editor.CaretLine).Length == 0)
						Editor.CaretColumn = Editor.GetVirtualIndentationColumn (Editor.CaretLine);
				} else {
					DoReSmartIndent ();
				}
			}

			return result;
		}
		// Called when a key is pressed in the editor.
		// Returns false if the key press has to continue normal processing.
		internal static bool ProcessKeyEvent (CompletionTextEditorExtension ext, ICompletionWidget widget, KeyDescriptor descriptor)
		{
			if (currentMethodGroup == null)
				return false;

			if (descriptor.SpecialKey == SpecialKey.Down) {
				return OverloadDown (ext, widget);
			} else if (descriptor.SpecialKey == SpecialKey.Up) {
				return OverloadUp (ext, widget);
			}
			else if (descriptor.SpecialKey == SpecialKey.Escape) {
				HideWindow (ext, widget);
				return true;
			}
			return false;
		}
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			//insert the method name
			var buf = window.CompletionWidget;
			if (buf != null) {
				buf.Replace (window.CodeCompletionContext.TriggerOffset, buf.CaretOffset - window.CodeCompletionContext.TriggerOffset, methodInfo.Name);
			}
			
			//generate the codebehind method

			// TODO: Roslyn port.
//			if (codeBehindClassLocation != null && project != null)
//				BindingService.AddMemberToClass (project, codeBehindClass, codeBehindClassLocation, methodInfo, false);
//			else
//				BindingService.AddMemberToClass (project, codeBehindClass, codeBehindClass.Locations.First (), methodInfo, false);
		}
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			var buf = window.CompletionWidget;
			if (buf != null) {
				int deleteStartOffset = window.CodeCompletionContext.TriggerOffset;
				if (text.StartsWith (docTypeStart)) {
					int start = window.CodeCompletionContext.TriggerOffset - docTypeStart.Length;
					if (start >= 0) {
						string readback = buf.GetText (start, window.CodeCompletionContext.TriggerOffset);
						if (string.Compare (readback, docTypeStart, StringComparison.OrdinalIgnoreCase) == 0)
							deleteStartOffset -= docTypeStart.Length;
					}
				}
				
				buf.Replace (deleteStartOffset, buf.CaretOffset - deleteStartOffset, text);
			}
		}
		public override bool Handle (TextEditor editor, DocumentContext ctx, KeyDescriptor descriptor)
		{
			char closingBrace;
			if (!IsSupportedOpeningBrace (descriptor.KeyChar, out closingBrace)  || !CheckCodeContext (editor, ctx, editor.CaretOffset - 1, descriptor.KeyChar, default (CancellationToken)))
				return false;
			
			var session = CreateEditorSession (editor, ctx, editor.CaretOffset, descriptor.KeyChar, default (CancellationToken));
			session.SetEditor (editor);
			if (session == null | !((ICheckPointEditSession)session).CheckOpeningPoint (editor, ctx, default (CancellationToken)))
				return false;
			using (var undo = editor.OpenUndoGroup ()) {
				editor.EnsureCaretIsNotVirtual ();
				editor.InsertAtCaret (closingBrace.ToString ());
				editor.CaretOffset--;
				editor.StartSession (session);
			}
			return true;
		}
Exemplo n.º 13
0
        public static string GetCurrentWord(CompletionListWindow window, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
        {
            int partialWordLength = window.PartialWord != null ? window.PartialWord.Length : 0;
            int replaceLength;

            if (descriptor.SpecialKey == SpecialKey.Return || descriptor.SpecialKey == SpecialKey.Tab)
            {
                replaceLength = window.CodeCompletionContext.TriggerWordLength + partialWordLength - window.InitialWordLength;
            }
            else
            {
                replaceLength = partialWordLength;
            }
            int endOffset = Math.Min(window.StartOffset + replaceLength, window.CompletionWidget.TextLength);
            var result    = window.CompletionWidget.GetText(window.StartOffset, endOffset);

            return(result);
        }
Exemplo n.º 14
0
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            // generic mode escape handler
            if (
                (descriptor.ModifierKeys == 0 && descriptor.SpecialKey == SpecialKey.Escape) ||
                (descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == '[') ||
                (descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == 'c'))
            {
                CurrentMode.InternalDeactivate();
                CurrentMode = _requestedMode = _normalMode;
                CurrentMode.InternalActivate();
                return false;
            }

            var pass = CurrentMode.KeyPress (descriptor);

            var newMode = CurrentMode.RequestedMode;
            if (newMode == Mode.Normal)
                _requestedMode = _normalMode;
            else if (newMode == Mode.Insert)
                _requestedMode = _insertMode;
            else if (newMode == Mode.Visual)
            {
                _visualMode.Select = SelectMode.Normal;
                _requestedMode = _visualMode;
            }
            else if (newMode == Mode.VisualLine)
            {
                _visualMode.Select = SelectMode.Line;
                _requestedMode = _visualMode;
            }
            else if (newMode == Mode.Replace)
                _requestedMode = _replaceMode;

            if (_requestedMode != CurrentMode)
            {
                CurrentMode.RequestedMode = Mode.None;
                CurrentMode.InternalDeactivate();
                _requestedMode.InternalActivate();
                CurrentMode = _requestedMode;
            }

            return pass && base.KeyPress(descriptor);
        }
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            var result = base.KeyPress(descriptor);

            // if the AutoInsertMatchingBracket option was changed since initialization
            if (DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket != isEnabled)
            {
                SetEnabled(DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket);
            }

            if (isEnabled && !Editor.IsSomethingSelected)
            {
                foreach (var handler in handlers)
                {
                    if (handler.CanHandle(Editor))
                    {
                        handler.Handle(Editor, DocumentContext, descriptor);
                        break;
                    }
                }
            }

            return(result);
        }
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			if (!IsActiveExtension())
				return Next == null || Next.KeyPress (descriptor);
			return completionTextEditorExtension.KeyPress (descriptor);
		}
        public virtual async void RunParameterCompletionCommand()
        {
            if (Editor.SelectionMode == SelectionMode.Block || CompletionWidget == null)
            {
                return;
            }
            ParameterHintingResult cp = null;
            int cpos = Editor.CaretOffset;
            CodeCompletionContext ctx = CompletionWidget.CreateCodeCompletionContext(cpos);

            cp = await ParameterCompletionCommand(ctx);

            if (cp != null)
            {
                ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, cp);
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, KeyDescriptor.FromGtk(Gdk.Key.F, 'f', Gdk.ModifierType.None));
            }
        }
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			var task = ctx.GetPartialProjectionsAsync ();
			if (task != null)
				projections = task.Result;
			var projectedExtension = GetCurrentExtension();
			if (projectedExtension != null) {
				return projectedExtension.KeyPress (descriptor);
			}
			return base.KeyPress (descriptor);
		}
Exemplo n.º 19
0
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			if (Editor.Options.IndentStyle == IndentStyle.Smart) {
				var newLine = Editor.CaretLine + 1;
				var ret = base.KeyPress (descriptor);
				if (descriptor.SpecialKey == SpecialKey.Return && Editor.CaretLine == newLine) {
					string indent = GetLineIndent (newLine);
					var oldIndent = Editor.GetLineIndent (newLine);
					var seg = Editor.GetLine (newLine);
					if (oldIndent != indent) {
						using (var undo = Editor.OpenUndoGroup ()) {
							Editor.ReplaceText (seg.Offset, oldIndent.Length, indent);
						}
					}
				}
				return ret;
			}
			return base.KeyPress (descriptor);
		}
		// When a key is pressed, and before the key is processed by the editor, this method will be invoked.
		// Return true if the key press should be processed by the editor.
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			bool res;
			if (CurrentCompletionContext != null) {
				if (CompletionWindowManager.PreProcessKeyEvent (descriptor)) {
					CompletionWindowManager.PostProcessKeyEvent (descriptor);
					autoHideCompletionWindow = true;
					// in named parameter case leave the parameter window open.
					autoHideParameterWindow = descriptor.KeyChar != ':';
					if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible)
						ParameterInformationWindowManager.PostProcessKeyEvent (this, CompletionWidget, descriptor);

					return false;
				}
				autoHideCompletionWindow = autoHideParameterWindow = false;
			}

			if (ParameterInformationWindowManager.IsWindowVisible) {
				if (ParameterInformationWindowManager.ProcessKeyEvent (this, CompletionWidget, descriptor))
					return false;
				autoHideCompletionWindow = autoHideParameterWindow = false;
			}

			//			int oldPos = Editor.CursorPosition;
			//			int oldLen = Editor.TextLength;
			char deleteOrBackspaceTriggerChar = '\0';
			if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length)
				deleteOrBackspaceTriggerChar = Editor.GetCharAt (Editor.CaretOffset);
			if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0)
				deleteOrBackspaceTriggerChar = Editor.GetCharAt (Editor.CaretOffset - 1);
			
			res = base.KeyPress (descriptor);

			CompletionWindowManager.PostProcessKeyEvent (descriptor);

			var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt
				| ModifierKeys.Command;
			// Handle parameter completion
			if (ParameterInformationWindowManager.IsWindowVisible) {
				ParameterInformationWindowManager.PostProcessKeyEvent (this, CompletionWidget, descriptor);
			}

			if ((descriptor.ModifierKeys & ignoreMods) != 0)
				return res;

			// don't complete on block selection
			if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
				return res;
			// Handle code completion
			if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible) {
				CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
				completionTokenSrc.Cancel ();
				completionTokenSrc = new CancellationTokenSource ();
				var caretOffset = Editor.CaretOffset;
				var token = completionTokenSrc.Token;
				try {
					var task = HandleCodeCompletionAsync (CurrentCompletionContext, descriptor.KeyChar, token);
					if (task != null) {
						// Show the completion window in two steps. The call to PrepareShowWindow creates the window but
						// it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
						CompletionWindowManager.PrepareShowWindow (this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
						EventHandler windowClosed = delegate (object o, EventArgs a) {
							completionTokenSrc.Cancel ();
						};
						CompletionWindowManager.WindowClosed += windowClosed;

						task.ContinueWith (t => {
							CompletionWindowManager.WindowClosed -= windowClosed;
							if (token.IsCancellationRequested)
								return;
							var result = t.Result;
							if (result != null) {
								int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

								if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset
								                              || (triggerWordLength == 1 && Editor.CaretOffset == 1))) {
									CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset - triggerWordLength);
									CurrentCompletionContext.TriggerWordLength = triggerWordLength;
								}
								// Now show the window for real.
								if (!CompletionWindowManager.ShowWindow (result, CurrentCompletionContext))
									CurrentCompletionContext = null;
							} else {
								CompletionWindowManager.HideWindow ();
								CurrentCompletionContext = null;
							}
						}, Runtime.MainTaskScheduler);
					} else {
						CurrentCompletionContext = null;
					}
				} catch (TaskCanceledException) {
					CurrentCompletionContext = null;
				} catch (AggregateException) {
					CurrentCompletionContext = null;
				}
			}

			if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible) {
				CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

				int cpos, wlen;
				if (!GetCompletionCommandOffset (out cpos, out wlen)) {
					cpos = Editor.CaretOffset;
					wlen = 0;
				}
				CurrentCompletionContext.TriggerOffset = cpos;
				CurrentCompletionContext.TriggerWordLength = wlen;
				
				completionTokenSrc.Cancel ();
				completionTokenSrc = new CancellationTokenSource ();
				var caretOffset = Editor.CaretOffset;
				var token = completionTokenSrc.Token;
				try {
					var task = HandleBackspaceOrDeleteCodeCompletionAsync (CurrentCompletionContext, descriptor.SpecialKey, deleteOrBackspaceTriggerChar, token);
					if (task != null) {
						// Show the completion window in two steps. The call to PrepareShowWindow creates the window but
						// it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
						CompletionWindowManager.PrepareShowWindow (this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
						EventHandler windowClosed = delegate (object o, EventArgs a) {
							completionTokenSrc.Cancel ();
						};
						CompletionWindowManager.WindowClosed += windowClosed;

						task.ContinueWith (t => {
							CompletionWindowManager.WindowClosed -= windowClosed;
							if (token.IsCancellationRequested)
								return;
							var result = t.Result;
							if (result != null) {
								int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

								if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset
								                              || (triggerWordLength == 1 && Editor.CaretOffset == 1))) {
									CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext (Editor.CaretOffset - triggerWordLength);
									CurrentCompletionContext.TriggerWordLength = triggerWordLength;
								}
								// Now show the window for real.
								if (!CompletionWindowManager.ShowWindow (result, CurrentCompletionContext)) {
									CurrentCompletionContext = null;
								} else {
									CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset;
									CompletionWindowManager.Wnd.EndOffset = Editor.CaretOffset;
								}
							} else {
								CompletionWindowManager.HideWindow ();
								CurrentCompletionContext = null;
							}
						}, Runtime.MainTaskScheduler);
					} else {
						CurrentCompletionContext = null;
					}
				} catch (TaskCanceledException) {
					CurrentCompletionContext = null;
				} catch (AggregateException) {
					CurrentCompletionContext = null;
				}
			}

			if (CompletionWidget != null) {
				CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext;
				parameterHintingSrc.Cancel ();
				parameterHintingSrc = new CancellationTokenSource ();
				var token = parameterHintingSrc.Token;
				try {
					var task = HandleParameterCompletionAsync (ctx, descriptor.KeyChar, token);
					if (task != null) {
						task.ContinueWith (t => {
							if (!token.IsCancellationRequested && t.Result != null)
								ParameterInformationWindowManager.ShowWindow (this, CompletionWidget, ctx, t.Result);
						}, Runtime.MainTaskScheduler);
					}
				} catch (TaskCanceledException) {
				} catch (AggregateException) {
				}

			}
			/*			autoHideCompletionWindow = true;
						autoHideParameterWindow = keyChar != ':';*/
			return res;
		}
//			public override TooltipInformation CreateTooltipInformation (bool smartWrap)
//			{
//				var sig = new SignatureMarkupCreator (ext.Editor, ext.DocumentContext, ext.Editor.CaretOffset);
//				sig.BreakLineAfterReturnType = smartWrap;
//				return sig.GetKeywordTooltip (title, null);
//			}

            public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
            {
                var currentWord = GetCurrentWord(window, descriptor);
                var text        = CompletionText;

                if (descriptor.KeyChar == '>' && text.EndsWith(">", StringComparison.Ordinal))
                {
                    text = text.Substring(0, text.Length - 1);
                }
                if (text.StartsWith("<", StringComparison.Ordinal))
                {
                    text = text.Substring(1);
                }

                window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, currentWord, text);
            }
Exemplo n.º 22
0
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            bool res;

            if (CurrentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(descriptor))
                {
                    CompletionWindowManager.PostProcessKeyEvent(descriptor);
                    autoHideCompletionWindow = true;
                    // in named parameter case leave the parameter window open.
                    autoHideParameterWindow = descriptor.KeyChar != ':';
                    if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible)
                    {
                        ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
                    }

                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor))
                {
                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            //			int oldPos = Editor.CursorPosition;
            //			int oldLen = Editor.TextLength;
            char deleteOrBackspaceTriggerChar = '\0';

            if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset);
            }
            if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1);
            }

            res = base.KeyPress(descriptor);

            CompletionWindowManager.PostProcessKeyEvent(descriptor);

            var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt
                             | ModifierKeys.Command;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
            }

            if ((descriptor.ModifierKeys & ignoreMods) != 0)
            {
                return(res);
            }

            // don't complete on block selection
            if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
            {
                return(res);
            }
            // Handle code completion
            if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

                int cpos, wlen;
                if (!GetCompletionCommandOffset(out cpos, out wlen))
                {
                    cpos = Editor.CaretOffset;
                    wlen = 0;
                }
                CurrentCompletionContext.TriggerOffset     = cpos;
                CurrentCompletionContext.TriggerWordLength = wlen;

                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleBackspaceOrDeleteCodeCompletionAsync(CurrentCompletionContext, descriptor.SpecialKey, deleteOrBackspaceTriggerChar, token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                                else
                                {
                                    CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset;
                                    CompletionWindowManager.Wnd.EndOffset   = Editor.CaretOffset;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if (CompletionWidget != null)
            {
                CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext;
                parameterHintingSrc.Cancel();
                parameterHintingSrc = new CancellationTokenSource();
                var token = parameterHintingSrc.Token;
                try {
                    var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        task.ContinueWith(t => {
                            if (!token.IsCancellationRequested && t.Result != null)
                            {
                                ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result);
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }

            /*			autoHideCompletionWindow = true;
             *                      autoHideParameterWindow = keyChar != ':';*/
            return(res);
        }
Exemplo n.º 23
0
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			if (descriptor.SpecialKey == SpecialKey.Escape && DebuggingService.ExceptionCaughtMessage != null &&
				!DebuggingService.ExceptionCaughtMessage.IsMinimized &&
				DebuggingService.ExceptionCaughtMessage.File.CanonicalPath == new FilePath (DocumentContext.Name).CanonicalPath) {

				DebuggingService.ExceptionCaughtMessage.ShowMiniButton ();
				return true;
			}

			return base.KeyPress (descriptor);
		}
		public override bool KeyPress (KeyDescriptor descriptor)
		{
			completionWindowWasVisible = CompletionWindowManager.IsVisible;
			cursorPositionBeforeKeyPress = Editor.CaretOffset;
			bool isSomethingSelected = Editor.IsSomethingSelected;
			if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset == lastInsertedSemicolon) {
				EditActions.Undo (Editor);
				lastInsertedSemicolon = -1;
				return false;
			}

			lastInsertedSemicolon = -1;
			if (descriptor.KeyChar == ';' && Editor.EditMode == EditMode.Edit && !DoInsertTemplate () && !isSomethingSelected && PropertyService.Get (
				    "SmartSemicolonPlacement",
				    false
			    ) && !(stateTracker.IsInsideComment || stateTracker.IsInsideString)) {
				bool retval = base.KeyPress (descriptor);
				var curLine = Editor.GetLine (Editor.CaretLine);
				string text = Editor.GetTextAt (curLine);
				if (!(text.EndsWith (";", StringComparison.Ordinal) || text.Trim ().StartsWith ("for", StringComparison.Ordinal))) {
					int guessedOffset;

					if (GuessSemicolonInsertionOffset (Editor, curLine, Editor.CaretOffset, out guessedOffset)) {
						using (var undo = Editor.OpenUndoGroup ()) {
							Editor.RemoveText (Editor.CaretOffset - 1, 1);
							Editor.CaretOffset = guessedOffset;
							lastInsertedSemicolon = Editor.CaretOffset + 1;
							retval = base.KeyPress (descriptor);
						}
					}
				}
				using (var undo = Editor.OpenUndoGroup ()) {
					if (OnTheFlyFormatting && Editor != null && Editor.EditMode == EditMode.Edit) {
						OnTheFlyFormatter.FormatStatmentAt (Editor, DocumentContext, Editor.CaretLocation, optionSet: optionSet);
					}
				}
				return retval;
			}
			
			if (descriptor.SpecialKey == SpecialKey.Tab && descriptor.ModifierKeys == ModifierKeys.None && !CompletionWindowManager.IsVisible) {
				SafeUpdateIndentEngine (Editor.CaretOffset);
				if (stateTracker.IsInsideStringLiteral && !Editor.IsSomethingSelected) {
					var lexer = new ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngineBase.MiniLexer (Editor.GetTextAt (0, Editor.CaretOffset));
					lexer.Parse ();
					if (lexer.IsInString) {
						Editor.InsertAtCaret ("\\t");
						return false;
					}
				}
			}


			if (descriptor.SpecialKey == SpecialKey.Tab && DefaultSourceEditorOptions.Instance.TabIsReindent && !CompletionWindowManager.IsVisible && Editor.EditMode == EditMode.Edit && !DoInsertTemplate () && !isSomethingSelected) {
				ReindentOnTab ();

				return false;
			}

			SafeUpdateIndentEngine (Editor.CaretOffset);
			if (!stateTracker.IsInsideOrdinaryCommentOrString) {
				if (descriptor.KeyChar == '@') {
					var retval = base.KeyPress (descriptor);
					int cursor = Editor.CaretOffset;
					if (cursor < Editor.Length && Editor.GetCharAt (cursor) == '"')
						ConvertNormalToVerbatimString (Editor, cursor + 1);
					return retval;
				}
			}


			//do the smart indent
			if (!indentationDisabled) {
				bool retval;
				//capture some of the current state
				int oldBufLen = Editor.Length;
				int oldLine = Editor.CaretLine + 1;
				bool reIndent = false;

				//pass through to the base class, which actually inserts the character
				//and calls HandleCodeCompletion etc to handles completion
				using (var undo = Editor.OpenUndoGroup ()) {
					DoPreInsertionSmartIndent (descriptor.SpecialKey);
				}
				wasInStringLiteral = stateTracker.IsInsideStringLiteral;
				bool automaticReindent;
				// need to be outside of an undo group - otherwise it interferes with other text editor extension
				// esp. the documentation insertion undo steps.
				retval = base.KeyPress (descriptor);
				//handle inserted characters
				if (Editor.CaretOffset <= 0 || Editor.IsSomethingSelected)
					return retval;
				
				lastCharInserted = TranslateKeyCharForIndenter (descriptor.SpecialKey, descriptor.KeyChar, Editor.GetCharAt (Editor.CaretOffset - 1));
				if (lastCharInserted == '\0')
					return retval;
				using (var undo = Editor.OpenUndoGroup ()) {
					SafeUpdateIndentEngine (Editor.CaretOffset);

					if (descriptor.SpecialKey == SpecialKey.Return && descriptor.ModifierKeys == ModifierKeys.Control) {
						FixLineStart (Editor, stateTracker, Editor.CaretLine + 1);
					} else {
						if (!(oldLine == Editor.CaretLine + 1 && lastCharInserted == '\n') && (oldBufLen != Editor.Length || lastCharInserted != '\0')) {
							DoPostInsertionSmartIndent (lastCharInserted, out reIndent);
						} else {
							reIndent = lastCharInserted == '\n';
						}
					}
					//reindent the line after the insertion, if needed
					//N.B. if the engine says we need to reindent, make sure that it's because a char was 
					//inserted rather than just updating the stack due to moving around

					SafeUpdateIndentEngine (Editor.CaretOffset);
					// Automatically reindent in text link mode will cause the mode exiting, therefore we need to prevent that.
					automaticReindent = (stateTracker.NeedsReindent && lastCharInserted != '\0') && Editor.EditMode == EditMode.Edit;
					if (descriptor.SpecialKey == SpecialKey.Return && (reIndent || automaticReindent)) {
						if (Editor.Options.IndentStyle == IndentStyle.Virtual) {
							if (Editor.GetLine (Editor.CaretLine).Length == 0)
								Editor.CaretColumn = Editor.GetVirtualIndentationColumn (Editor.CaretLine);
						} else {
							DoReSmartIndent ();
						}
					}
				}

				const string reindentChars = ";){}";
				if (reIndent || descriptor.SpecialKey != SpecialKey.Return && descriptor.SpecialKey != SpecialKey.Tab && automaticReindent && reindentChars.Contains (descriptor.KeyChar)) {
					using (var undo = Editor.OpenUndoGroup ()) {
						DoReSmartIndent ();
					}
				}

				HandleOnTheFlyFormatting (descriptor);
				SafeUpdateIndentEngine (Editor.CaretOffset);
				lastCharInserted = '\0';
				CheckXmlCommentCloseTag (descriptor.KeyChar);
				return retval;
			}

			if (Editor.Options.IndentStyle == IndentStyle.Auto && DefaultSourceEditorOptions.Instance.TabIsReindent && descriptor.SpecialKey == SpecialKey.Tab) {
				bool retval = base.KeyPress (descriptor);
				DoReSmartIndent ();
				CheckXmlCommentCloseTag (descriptor.KeyChar);
				return retval;
			}

			//pass through to the base class, which actually inserts the character
			//and calls HandleCodeCompletion etc to handles completion
			var result = base.KeyPress (descriptor);

			if (!indentationDisabled && (descriptor.SpecialKey == SpecialKey.Return)) {
				DoReSmartIndent ();
			}

			CheckXmlCommentCloseTag (descriptor.KeyChar);

			HandleOnTheFlyFormatting (descriptor);
			
			return result;
		}
		void HandleOnTheFlyFormatting (KeyDescriptor descriptor)
		{
			if (descriptor.KeyChar == '{')
				return;
			SafeUpdateIndentEngine (Editor.CaretOffset);
			bool skipFormatting = stateTracker.IsInsideOrdinaryCommentOrString || stateTracker.IsInsidePreprocessorDirective;
			if (!skipFormatting && !(stateTracker.IsInsideComment || stateTracker.IsInsideString)) {
				if (DocumentContext.ParsedDocument == null || DocumentContext.ParsedDocument.GetAst<SemanticModel> () == null)
					return;
				var document = DocumentContext.AnalysisDocument;
				if (document == null)
					return;
				if (!skipFormatting && service.SupportsFormattingOnTypedCharacter (document, descriptor.KeyChar)) {
					var caretPosition = Editor.CaretOffset;
					var token = CSharpEditorFormattingService.GetTokenBeforeTheCaretAsync (document, caretPosition, default(CancellationToken)).Result;
					if (token.IsMissing || !service.ValidSingleOrMultiCharactersTokenKind (descriptor.KeyChar, token.Kind ()) || token.IsKind (SyntaxKind.EndOfFileToken, SyntaxKind.None))
						return;
					if (CSharpEditorFormattingService.TokenShouldNotFormatOnTypeChar (token))
						return;
					using (var undo = Editor.OpenUndoGroup ()) {
						if (OnTheFlyFormatting && Editor != null && Editor.EditMode == EditMode.Edit) {
							OnTheFlyFormatter.FormatStatmentAt (Editor, DocumentContext, Editor.CaretLocation, optionSet: optionSet);
						}
					}
				}
			}
			if (OnTheFlyFormatting && descriptor.SpecialKey == SpecialKey.Return) {
				try {
					FormatOnReturn ();
				} catch (Exception e) {
					LoggingService.LogError ("Exception while formatting", e);
				}
			}
		}
		internal static void PostProcessKeyEvent (CompletionTextEditorExtension ext, ICompletionWidget widget, KeyDescriptor descriptor)
		{
		}
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            if ((descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == 'f') ||
                (descriptor.ModifierKeys == 0 && descriptor.SpecialKey == SpecialKey.PageDown))
            {
                EditActions.ScrollPageDown(Editor);
                return false;
            }

            if ((descriptor.ModifierKeys == ModifierKeys.Control && descriptor.KeyChar == 'b') ||
                (descriptor.ModifierKeys == 0 && descriptor.SpecialKey == SpecialKey.PageUp))
            {
                EditActions.ScrollPageUp(Editor);
                return false;
            }

            if (descriptor.ModifierKeys == 0)
            {
                uint unicodeKey = descriptor.KeyChar;

                // remap some function keys to Vi commands
                if (descriptor.SpecialKey == SpecialKey.Home)
                    unicodeKey = '0';
                else if (descriptor.SpecialKey == SpecialKey.End)
                    unicodeKey = '$';
                else if (descriptor.SpecialKey == SpecialKey.Left)
                    unicodeKey = 'h';
                else if (descriptor.SpecialKey == SpecialKey.Right)
                    unicodeKey = 'l';
                else if (descriptor.SpecialKey == SpecialKey.Up)
                    unicodeKey = 'k';
                else if (descriptor.SpecialKey == SpecialKey.Down)
                    unicodeKey = 'j';
                else if (descriptor.SpecialKey == SpecialKey.Delete)
                    unicodeKey = 'x';
                //else if (descriptor.SpecialKey == SpecialKey.Insert)
                //    unicodeKey = 'i';
                else if (descriptor.SpecialKey == SpecialKey.BackSpace)
                    unicodeKey = 'h';

                if (_command == null)
                {
                    // build repeat buffer
                    if ((_countString.Length > 0 || unicodeKey > '0') && unicodeKey >= '0' && unicodeKey <= '9')
                    {
                        _countString += Char.ToString((char)unicodeKey);
                        return false;
                    }

                    _command = unicodeKey;
                }
                else
                {
                    _commandArgs.Add((char)unicodeKey);
                }

                if (!_commands.ContainsKey((uint)_command))
                {
                    _command = null;
                    return false;
                }

                CaretOffEol();

                if (_commands[(uint)_command](Count, _commandArgs.ToArray()))
                {
                    Reset();
                }
            }

            return false;
        }
Exemplo n.º 28
0
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            var ret = base.KeyPress(descriptor);

            if (RequestedMode == Mode.None)
            {
                UpdateSelection();
            }

            return ret;
        }
Exemplo n.º 29
0
        public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
        {
            string partialWord = GetCurrentWord(window, descriptor);
            int    skipChars   = 0;
            bool   runParameterCompletionCommand  = false;
            bool   runCompletionCompletionCommand = false;
            var    method = Symbol as IMethodSymbol;

            bool   addParens      = IdeApp.Preferences.AddParenthesesAfterCompletion;
            bool   addOpeningOnly = IdeApp.Preferences.AddOpeningOnly;
            var    Editor         = ext.Editor;
            var    Policy         = ext.FormattingPolicy;
            string insertionText  = this.GetInsertionText();

            if (addParens && !IsDelegateExpected && method != null && !IsBracketAlreadyInserted(ext, method))
            {
                var line = Editor.GetLine(Editor.CaretLine);
                //var start = window.CodeCompletionContext.TriggerOffset + partialWord.Length + 2;
                //var end = line.Offset + line.Length;
                //string textToEnd = start < end ? Editor.GetTextBetween (start, end) : "";
                bool addSpace = Policy.SpaceAfterMethodCallName && MonoDevelop.Ide.Editor.DefaultSourceEditorOptions.Instance.OnTheFlyFormatting;

                int exprStart = window.CodeCompletionContext.TriggerOffset - 1;
                while (exprStart > line.Offset)
                {
                    char ch = Editor.GetCharAt(exprStart);
                    if (ch != '.' && ch != '_' && !char.IsLetterOrDigit(ch))
                    {
                        break;
                    }
                    exprStart--;
                }
                bool insertSemicolon = InsertSemicolon(ext, exprStart);
                if (Symbol is IMethodSymbol && ((IMethodSymbol)Symbol).MethodKind == MethodKind.Constructor)
                {
                    insertSemicolon = false;
                }
                //int pos;

                var keys = new [] { SpecialKey.Return, SpecialKey.Tab, SpecialKey.Space };
                if (keys.Contains(descriptor.SpecialKey) || descriptor.KeyChar == '.')
                {
                    if (HasAnyOverloadWithParameters(method))
                    {
                        if (addOpeningOnly)
                        {
                            insertionText += RequireGenerics(method) ? "<|" : (addSpace ? " (|" : "(|");
                            skipChars      = 0;
                        }
                        else
                        {
                            if (descriptor.KeyChar == '.')
                            {
                                if (RequireGenerics(method))
                                {
                                    insertionText += addSpace ? "<> ()" : "<>()";
                                }
                                else
                                {
                                    insertionText += addSpace ? " ()" : "()";
                                }
                                skipChars = 0;
                            }
                            else
                            {
                                if (insertSemicolon)
                                {
                                    if (RequireGenerics(method))
                                    {
                                        insertionText += addSpace ? "<|> ();" : "<|>();";
                                        skipChars      = addSpace ? 5 : 4;
                                    }
                                    else
                                    {
                                        insertionText += addSpace ? " (|);" : "(|);";
                                        skipChars      = 2;
                                    }
                                }
                                else
                                {
                                    if (RequireGenerics(method))
                                    {
                                        insertionText += addSpace ? "<|> ()" :  "<|>()";
                                        skipChars      = addSpace ? 4 : 3;
                                    }
                                    else
                                    {
                                        insertionText += addSpace ? " (|)" : "(|)";
                                        skipChars      = 1;
                                    }
                                }
                            }
                        }
                        runParameterCompletionCommand = true;
                    }
                    else
                    {
                        if (addOpeningOnly)
                        {
                            insertionText += RequireGenerics(method) ? "<|" : (addSpace ? " (|" : "(|");
                            skipChars      = 0;
                        }
                        else
                        {
                            if (descriptor.KeyChar == '.')
                            {
                                if (RequireGenerics(method))
                                {
                                    insertionText += addSpace ? "<> ()" : "<>()";
                                }
                                else
                                {
                                    insertionText += addSpace ? " ()" : "()";
                                }
                                skipChars = 0;
                            }
                            else
                            {
                                if (insertSemicolon)
                                {
                                    if (RequireGenerics(method))
                                    {
                                        insertionText += addSpace ? "<|> ();" : "<|>();";
                                    }
                                    else
                                    {
                                        insertionText += addSpace ? " ();|" : "();|";
                                    }
                                }
                                else
                                {
                                    if (RequireGenerics(method))
                                    {
                                        insertionText += addSpace ? "<|> ()" : "<|>()";
                                    }
                                    else
                                    {
                                        insertionText += addSpace ? " ()|" : "()|";
                                    }
                                }
                            }
                        }
                    }
                }
                if (descriptor.KeyChar == ';')
                {
                    insertionText += addSpace ? " ()" : "()";
                }
                ka |= KeyActions.Ignore;
            }
            if ((DisplayFlags & DisplayFlags.NamedArgument) == DisplayFlags.NamedArgument &&
                IdeApp.Preferences.AddParenthesesAfterCompletion &&
                (descriptor.SpecialKey == SpecialKey.Tab ||
                 descriptor.SpecialKey == SpecialKey.Return ||
                 descriptor.SpecialKey == SpecialKey.Space))
            {
                if (true /*Policy.AroundAssignmentParentheses */)
                {
                    insertionText += " ";
                }
                insertionText += "=";
                if (/*Policy.AroundAssignmentParentheses && */ descriptor.SpecialKey != SpecialKey.Space)
                {
                    insertionText += " ";
                }
                runCompletionCompletionCommand = true;
            }
            window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, partialWord, insertionText);
            int offset = Editor.CaretOffset;

            for (int i = skipChars; i-- > 0;)
            {
                Editor.StartSession(new SkipCharSession(Editor.GetCharAt(offset + i)));
            }

            if (runParameterCompletionCommand && IdeApp.Workbench != null)
            {
                Application.Invoke(delegate {
                    ext.RunParameterCompletionCommand();
                });
            }

            if (runCompletionCompletionCommand && IdeApp.Workbench != null)
            {
                Application.Invoke(delegate {
                    ext.RunCompletionCommand();
                });
            }
        }
Exemplo n.º 30
0
			public override bool KeyPress (KeyDescriptor descriptor)
			{
				var native =(Tuple<Gdk.Key, Gdk.ModifierType>)descriptor.NativeKeyChar;
				ext.SimulateKeyPress (native.Item1, (uint)descriptor.KeyChar, native.Item2);
				if (descriptor.SpecialKey == SpecialKey.Escape)
					return true;
				return false;
			}
Exemplo n.º 31
0
        public virtual bool KeyPress(KeyDescriptor descriptor)
        {
            // build repeat buffer
            if (_command == null && (_count > 0 || descriptor.KeyChar > '0') && descriptor.KeyChar >= '0' && descriptor.KeyChar <= '9')
            {
                _count = (_count * 10) + (descriptor.KeyChar - 48);
                return false;
            }

            _buf += Char.ToString(descriptor.KeyChar);

            if (_command == null)
            {

                if (descriptor.ModifierKeys == ModifierKeys.Control)
                    _buf = "^" + _buf;

                if (!SpecialKeyCommandMap.TryGetValue(descriptor.SpecialKey, out _command))
                {
                    if (!CommandMap.ContainsKey(_buf))
                    {
                        foreach (var k in CommandMap.Keys)
                        {
                            if (k.StartsWith(_buf, StringComparison.Ordinal))
                                return false;
                        }

                        Reset();
                        return false;
                    }

                    _command = CommandMap[_buf];
                }

                _buf = "";
                if (_command.TakeArgument)
                    return false;
            }

            CaretOffEol();

            RequestedMode = _command.RunCommand(_count, (char)(_buf.Length > 0 ? _buf[0] : 0));
            _command = null;
            Reset();

            CaretOffEol();
            return false;
        }
Exemplo n.º 32
0
		public static bool PreProcessKeyEvent (KeyDescriptor descriptor)
		{
			if (!IsVisible)
				return false;
			if (descriptor.KeyChar != '\0') {
				wnd.EndOffset = wnd.StartOffset + wnd.CurrentPartialWord.Length + 1;
			}
			return wnd.PreProcessKeyEvent (descriptor);
		}
            public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
            {
                if (this.CompletionText == "sizeof" || this.CompletionText == "nameof" || this.CompletionText == "typeof")
                {
                    string partialWord = GetCurrentWord(window, descriptor);
                    int    skipChars   = 0;
                    bool   runCompletionCompletionCommand = false;
                    var    method = Symbol as IMethodSymbol;

                    bool   addParens     = DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket;
                    var    Editor        = ext.Editor;
                    var    Policy        = ext.FormattingPolicy;
                    string insertionText = this.CompletionText;

                    if (addParens && !IsBracketAlreadyInserted(ext))
                    {
                        var line = Editor.GetLine(Editor.CaretLine);
                        //var start = window.CodeCompletionContext.TriggerOffset + partialWord.Length + 2;
                        //var end = line.Offset + line.Length;
                        //string textToEnd = start < end ? Editor.GetTextBetween (start, end) : "";
                        bool addSpace = Policy.SpaceAfterMethodCallName && MonoDevelop.Ide.Editor.DefaultSourceEditorOptions.Instance.OnTheFlyFormatting;

                        var keys = new [] { SpecialKey.Return, SpecialKey.Tab, SpecialKey.Space };
                        if (keys.Contains(descriptor.SpecialKey) || descriptor.KeyChar == ' ')
                        {
                            insertionText += addSpace ? " (|)" : "(|)";
                        }
                        ka |= KeyActions.Ignore;
                    }

                    window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, partialWord, insertionText);
                    int offset = Editor.CaretOffset;
                    for (int i = skipChars - 1; i-- > 0;)
                    {
                        Editor.StartSession(new SkipCharSession(Editor.GetCharAt(offset)));
                        offset++;
                    }

                    if (runCompletionCompletionCommand && IdeApp.Workbench != null)
                    {
                        Application.Invoke((o, args) => {
                            ext.RunCompletionCommand();
                        });
                    }
                }
                else
                {
                    base.InsertCompletionText(window, ref ka, descriptor);
                }
            }
Exemplo n.º 34
0
 /// <summary>
 /// Return true if the key press should be processed by the editor.
 /// When a key is pressed, and before the key is processed by the editor, this method will be invoked.
 /// </summary>
 public virtual async Task <bool> KeyPress(KeyDescriptor descriptor)
 {
     return(Next == null || await Next.KeyPress(descriptor));
 }
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			// insert add/remove event handler code after +=/-=
			var editor = factory.Ext.Editor;


			bool AddSemicolon = true;
			var position = window.CodeCompletionContext.TriggerOffset;
			editor.ReplaceText (position, editor.CaretOffset - position, this.DisplayText + (AddSemicolon ? ";" : ""));


			var document = IdeApp.Workbench.ActiveDocument;
			var parsedDocument = document.UpdateParseDocument ().Result;
			var semanticModel = parsedDocument.GetAst<SemanticModel> ();

			var declaringType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol> (position, default(CancellationToken));
			var enclosingSymbol = semanticModel.GetEnclosingSymbol<ISymbol> (position, default(CancellationToken));

			var insertionPoints = InsertionPointService.GetInsertionPoints (
				document.Editor,
				parsedDocument,
				declaringType,
				editor.CaretOffset
			);
			var options = new InsertionModeOptions (
				GettextCatalog.GetString ("Create new method"),
				insertionPoints,
				point => {
					if (!point.Success) 
						return;
					var indent = "\t";
					var sb = new StringBuilder ();
					if (enclosingSymbol != null && enclosingSymbol.IsStatic)
						sb.Append ("static ");
					sb.Append ("void ");
					int pos2 = sb.Length;
					sb.Append (this.DisplayText);
					sb.Append (' ');
					sb.Append("(");

					var delegateMethod = delegateType.GetDelegateInvokeMethod();
					for (int k = 0; k < delegateMethod.Parameters.Length; k++) {
						if (k > 0) {
							sb.Append(", ");
						}
						sb.Append (RoslynCompletionData.SafeMinimalDisplayString (delegateMethod.Parameters [k], semanticModel, position, MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat)); 
					}
					sb.Append(")");

					sb.Append (editor.EolMarker);
					sb.Append (indent);
					sb.Append ("{");
					sb.Append (editor.EolMarker);
					sb.Append (indent);
					sb.Append (editor.Options.GetIndentationString ());
					//int cursorPos = pos + sb.Length;
					sb.Append (editor.EolMarker);
					sb.Append (indent);
					sb.Append ("}");
					point.InsertionPoint.Insert (document.Editor, document, sb.ToString ());
					//			// start text link mode after insert
					//			var links = new List<TextLink> ();
					//			var link = new TextLink ("name");
					//			
					//			link.AddLink (new TextSegment (initialOffset, this.DisplayText.Length));
					//			link.AddLink (new TextSegment (initialOffset + pos + pos2, this.DisplayText.Length));
					//			links.Add (link);
					//			editor.StartTextLinkMode (new TextLinkModeOptions (links));
				}
			);

			editor.StartInsertionMode (options);

		}
		public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
		{
			var editor = ext.Editor;
			bool isExplicit = false;
			//			if (member.DeclaringTypeDefinition.Kind == TypeKind.Interface) {
			//				foreach (var m in type.Members) {
			//					if (m.Name == member.Name && !m.ReturnType.Equals (member.ReturnType)) {
			//						isExplicit = true;
			//						break;
			//					}
			//				}
			//			}
			//			var resolvedType = type.Resolve (ext.Project).GetDefinition ();
			//			if (ext.Project != null)
			//				generator.PolicyParent = ext.Project.Policies;

			var result = CSharpCodeGenerator.CreatePartialMemberImplementation (ext.DocumentContext, ext.Editor, currentType, currentType.Locations.First (), Symbol, isExplicit, factory.SemanticModel);
			string sb = result.Code.TrimStart ();
			int trimStart = result.Code.Length - sb.Length;
			sb = sb.TrimEnd ();

			var lastRegion = result.BodyRegions.LastOrDefault ();
			var region = lastRegion == null? null
				: new CodeGeneratorBodyRegion (lastRegion.StartOffset - trimStart, lastRegion.EndOffset - trimStart);

			int targetCaretPosition;
			int selectionEndPosition = -1;
			if (region != null && region.IsValid) {
				targetCaretPosition = declarationBegin + region.EndOffset;

			} else {
				targetCaretPosition = declarationBegin + sb.Length;
			}

			editor.ReplaceText (declarationBegin, editor.CaretOffset - declarationBegin, sb);
			if (selectionEndPosition > 0) {
				editor.CaretOffset = selectionEndPosition;
				editor.SetSelection (targetCaretPosition, selectionEndPosition);
			} else {
				editor.CaretOffset = targetCaretPosition;
			}

			OnTheFlyFormatter.Format (editor, ext.DocumentContext, declarationBegin, declarationBegin + sb.Length);
			editor.CaretLine--;
		}
			public bool PostProcessKey (CompletionListWindow listWindow, KeyDescriptor descriptor, out KeyActions keyAction)
			{
				keyAction = KeyActions.None;
				if (descriptor.KeyChar == '.') {
					return true;
				}
				return false;
			}
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            if (!IsActiveExtension())
            {
                return(base.KeyPress(descriptor));
            }
            bool res;

            if (CurrentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(descriptor))
                {
                    CompletionWindowManager.PostProcessKeyEvent(descriptor);
                    autoHideCompletionWindow = true;
                    // in named parameter case leave the parameter window open.
                    autoHideParameterWindow = descriptor.KeyChar != ':';
                    if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible)
                    {
                        ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
                    }

                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor))
                {
                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            //			int oldPos = Editor.CursorPosition;
            //			int oldLen = Editor.TextLength;
            char deleteOrBackspaceTriggerChar = '\0';

            if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset);
            }
            if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1);
            }

            res = base.KeyPress(descriptor);
            if (Editor.EditMode == EditMode.TextLink && Editor.TextLinkPurpose == TextLinkPurpose.Rename)
            {
                return(res);
            }
            if (descriptor.KeyChar == (char)16 || descriptor.KeyChar == (char)17)
            {
                return(res);
            }

            CompletionWindowManager.PostProcessKeyEvent(descriptor);

            var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt
                             | ModifierKeys.Command;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
            }

            if ((descriptor.ModifierKeys & ignoreMods) != 0)
            {
                return(res);
            }

            // don't complete on block selection
            if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
            {
                return(res);
            }
            // Handle code completion
            if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                completionTokenSrc.Cancel();
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
                completionTokenSrc       = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.CharTyped, descriptor.KeyChar), token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;
                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);
                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    if (result.TriggerWordStart >= 0)
                                    {
                                        CurrentCompletionContext.TriggerOffset = result.TriggerWordStart;
                                    }
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }

            if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                if (!char.IsLetterOrDigit(deleteOrBackspaceTriggerChar) && deleteOrBackspaceTriggerChar != '_')
                {
                    return(res);
                }
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

                int cpos, wlen;
                if (!GetCompletionCommandOffset(out cpos, out wlen))
                {
                    cpos = Editor.CaretOffset;
                    wlen = 0;
                }

                CurrentCompletionContext.TriggerOffset     = cpos;
                CurrentCompletionContext.TriggerWordLength = wlen;

                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.BackspaceOrDeleteCommand, deleteOrBackspaceTriggerChar), token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    if (result.TriggerWordStart >= 0)
                                    {
                                        CurrentCompletionContext.TriggerOffset = result.TriggerWordStart;
                                    }
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                                else
                                {
                                    CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if (CompletionWidget != null)
            {
                CodeCompletionContext ctx  = CompletionWidget.CurrentCodeCompletionContext;
                var newparameterHintingSrc = new CancellationTokenSource();
                var token = newparameterHintingSrc.Token;
                try {
                    var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        parameterHintingSrc.Cancel();
                        parameterHintingSrc = newparameterHintingSrc;
                        parameterHingtingCursorPositionChanged = false;
                        task.ContinueWith(t => {
                            if (!token.IsCancellationRequested && t.Result != null)
                            {
                                ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result);
                                if (parameterHingtingCursorPositionChanged)
                                {
                                    ParameterInformationWindowManager.UpdateCursorPosition(this, CompletionWidget);
                                }
                            }
                        }, token, TaskContinuationOptions.None, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        //Key was typed that was filtered out, no heavy processing will be performed(task==null)
                        //but we still want to update ParameterInfo window to avoid displaying it outside method call
                        parameterHingtingCursorPositionChanged = true;
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }
            return(res);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Return true if the key press should be processed by the editor.
 /// When a key is pressed, and before the key is processed by the editor, this method will be invoked.
 /// </summary>
 public virtual bool KeyPress(KeyDescriptor descriptor)
 {
     return(Next == null || Next.KeyPress(descriptor));
 }
		public override bool Handle (TextEditor editor, DocumentContext ctx, KeyDescriptor descriptor)
		{
			int braceIndex = openBrackets.IndexOf (descriptor.KeyChar);
			if (braceIndex < 0)
				return false;
			
			var extEditor = ((SourceEditorView)editor.Implementation).SourceEditorWidget.TextEditor;

			var line = extEditor.Document.GetLine (extEditor.Caret.Line);
			if (line == null)
				return false;

			bool inStringOrComment = false;

			var stack = line.StartSpan.Clone ();
			var sm = extEditor.Document.SyntaxMode as SyntaxMode;
			if (sm != null)
				// extEditor.Caret.Offset - 1 means we care if we were inside string
				// before typing current char
				Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (extEditor.Document, sm, sm, stack, line.Offset, extEditor.Caret.Offset - 1);
			foreach (var span in stack) {
				if (string.IsNullOrEmpty (span.Color))
					continue;
				if (span.Color.StartsWith ("String", StringComparison.Ordinal) ||
				    span.Color.StartsWith ("Comment", StringComparison.Ordinal) ||
				    span.Color.StartsWith ("Xml Attribute Value", StringComparison.Ordinal)) {
					inStringOrComment = true;
					break;
				}
			}
			char insertionChar = '\0';
			bool insertMatchingBracket = false;
			if (!inStringOrComment) {
				char closingBrace = closingBrackets [braceIndex];
				char openingBrace = openBrackets [braceIndex];

				int count = 0;
				foreach (char curCh in ExtensibleTextEditor.GetTextWithoutCommentsAndStrings(extEditor.Document, 0, extEditor.Document.TextLength)) {
					if (curCh == openingBrace) {
						count++;
					} else if (curCh == closingBrace) {
						count--;
					}
				}

				if (count >= 0) {
					insertMatchingBracket = true;
					insertionChar = closingBrace;
				}
			}

			if (insertMatchingBracket) {
				using (var undo = editor.OpenUndoGroup ()) {
					editor.EnsureCaretIsNotVirtual ();
					editor.InsertAtCaret (insertionChar.ToString ());
					editor.CaretOffset--;
					editor.StartSession (new SkipCharSession (insertionChar));
				}
				return true;
			}

			return false;
		}
Exemplo n.º 41
0
		public static void PostProcessKeyEvent (KeyDescriptor descriptor)
		{
			if (!IsVisible)
				return;
			wnd.PostProcessKeyEvent (descriptor);
		}
 public abstract bool Handle(TextEditor editor, DocumentContext ctx, KeyDescriptor descriptor);