/// <summary> /// Handles the key up event. /// The intellisense window is dismissed when one presses ESC key /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnKeyUp(object sender, KeyEventArgs e) { if (activeSession != null) { if (e.Key == Key.Escape) { activeSession.Dismiss(); e.Handled = true; } if (e.Key == Key.Enter) { if (this.activeSession.SelectedCompletionSet.SelectionStatus != null && this.activeSession.SelectedCompletionSet.SelectionStatus.IsSelected) { selectedCompletionBeforeCommit = this.activeSession.SelectedCompletionSet.SelectionStatus.Completion as RegexCompletion; activeSession.Commit(); } else { activeSession.Dismiss(); } e.Handled = true; } } }
/// <summary> /// Tries to end auto completion based on the currently pressed keys. /// </summary> /// <param name="typedChar">The currently typed character, if any.</param> /// <param name="nCmdID">Key command id.</param> /// <returns>True if the auto completion committed.</returns> private bool TryEndCompletion(char typedChar, uint nCmdID) { // Dismiss the session on space. if (typedChar == ' ') { m_session.Dismiss(); } // Check for a commit key. else if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB) { // If the selection is fully selected, commit the current session. if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected) { string selectedCompletion = m_session.SelectedCompletionSet.SelectionStatus.Completion.DisplayText; m_session.Commit(); return(true); } else { // if there is no selection, dismiss the session m_session.Dismiss(); } } return(false); }
private void Dismiss() { if (_activeSession != null) { _activeSession.Dismiss(); } }
/// <summary> /// Cancel the auto-complete session, and leave the text unmodified /// </summary> private void Cancel() { if (null != _currentSession) { _currentSession.Dismiss(); } }
private bool Complete(bool force) { // Handle non-existant Sessions if (_currentSession == null) { //auto-complete after auto-complete (we are not the only ones) var timer = new DispatcherTimer(); timer.Tick += (o, e) => { timer.Stop(); StartSession(); }; timer.Interval = TimeSpan.FromMilliseconds(100); timer.Start(); return(false); } // Based off of the available selection, determine if it should be dismissed (via Dismiss) or // output (via Commit) if (!_currentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force) { _currentSession.Dismiss(); return(false); } else { _currentSession.Commit(); return(true); } }
protected void FilterAutoComplete(char ch) { if (!IsAutoCompleteSessionActive) { return; } currentAutoCompleteSession.SelectedCompletionSet.Filter(); currentAutoCompleteSession.SelectedCompletionSet.SelectBestMatch(); currentAutoCompleteSession.SelectedCompletionSet.Recalculate(); if (currentAutoCompleteSession.SelectedCompletionSet.SelectionStatus.IsSelected && currentAutoCompleteSession.SelectedCompletionSet.SelectionStatus.IsUnique) { string insertedText = currentAutoCompleteSession.SelectedCompletionSet.ApplicableTo.GetText(TextView.TextSnapshot); string selectedText = currentAutoCompleteSession.SelectedCompletionSet.SelectionStatus.Completion.InsertionText; if (insertedText.TrimEnd().Equals(selectedText.TrimEnd(), StringComparison.CurrentCulture)) { currentAutoCompleteSession.Dismiss(); return; } if (insertedText.TrimEnd().Equals(selectedText.TrimEnd(), StringComparison.CurrentCultureIgnoreCase)) { currentAutoCompleteSession.Commit(); return; } } if (!currentAutoCompleteSession.SelectedCompletionSet.SelectionStatus.IsSelected && ch == ' ' && IsPrefixMatch(currentAutoCompleteSession.SelectedCompletionSet)) { currentAutoCompleteSession.Dismiss(); StartAutoCompleteSession(ch); } }
private void RestartSession() { if (IsSessionStarted) { currentSession.Dismiss(); } StartSession(); }
bool CancelCompletionSession() { if (_completionSession == null) { return(false); } _completionSession.Dismiss(); return(true); }
/// <summary> /// Handles the key up event. /// The intellisense window is dismissed when one presses ESC key /// Pressing Enter key commits the session /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VisualElement_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) { // Make sure that this event happened on the same text view to which we're attached. ITextView textView = sender as ITextView; if (this.textView != textView) { return; } if (activeSession == null) { return; } switch (e.Key) { case Key.Space: case Key.Escape: activeSession.Dismiss(); e.Handled = true; return; case Key.Back: case Key.Left: if (textView.Caret.Position.BufferPosition.Position <= triggerPosition) { // we went too far to the left activeSession.Dismiss(); } return; case Key.Right: if (textView.Caret.Position.BufferPosition.Position > triggerPosition + completionSpan.GetSpan(completionSpan.TextBuffer.CurrentSnapshot).Length) { // we went too far to the right activeSession.Dismiss(); } return; case Key.Enter: if (this.activeSession.SelectedCompletionSet.SelectionStatus != null) { activeSession.Commit(); } else { activeSession.Dismiss(); } e.Handled = true; return; default: break; } }
bool Cancel() { if (_currentSession == null) { return(false); } _currentSession.Dismiss(); return(true); }
public bool Cancel() { if (m_session == null) { return(false); } m_session.Dismiss(); return(true); }
bool Cancel() { if (_currentSession == null) return false; _currentSession.Dismiss(); return true; }
bool Cancel() { this.Out("Cancel"); if (_currentSession == null) { return(false); } _currentSession.Dismiss(); return(true); }
private bool Cancel() { if (CurrentSession == null) { return(false); } CurrentSession.Dismiss(); return(true); }
public void TriggerCompletion(bool autoComplete) { if (_session != null) { _session.Dismiss(); } else { UpdateModel(); } }
/// <summary> /// Cancel the auto-complete session, and leave the text unmodified /// </summary> private bool Cancel() { if (_completionSession != null) { _completionSession.Dismiss(); return(true); } else { return(false); } }
/// <summary> /// 确认完成或者丢弃 /// </summary> private bool Complete(bool force) { if (_CurrentSession == null || !_CurrentSession.IsStarted) { return(false); } try { //如果用户没有选择并且主动丢弃 if (!_CurrentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force) { _CurrentSession.Dismiss(); return(false); } else { ITextEdit edit = _CurrentSession.TextView.TextBuffer.CreateEdit(); ITextSnapshot snapshot = edit.Snapshot; string inputtext = _CurrentSession.TextView.Caret.Position.BufferPosition.GetContainingLine().GetText(); var inputlist = Core.UsuallyCommon.SearchExtensions.GetStringSingleColumn(inputtext); var starttext = inputlist.LastOrDefault(); string lastChar = starttext.Substring(starttext.Length - 1, 1); starttext = starttext.Replace(lastChar, "").Trim(); int position = (starttext.LastIndexOf(" ") > 0) ? (starttext.Length + 1 - starttext.LastIndexOf(" ")) : (starttext.LastIndexOf("\t") > 0 ? (starttext.Length + 1 - starttext.LastIndexOf("\t")) : starttext.Length + 1); edit.Delete(_CurrentSession.TextView.Caret.Position.BufferPosition.Position - position, position); string text = _CurrentSession.SelectedCompletionSet.SelectionStatus.Completion.InsertionText; edit.Insert(_CurrentSession.TextView.Caret.Position.BufferPosition.Position - position, text); edit.Apply(); if (_CurrentSession != null) { _CurrentSession.Dismiss(); } return(true); } } catch (Exception ex) { DataServices.AddExexptionLogs(ex, "Complete 方法错误"); } return(true); }
private void OpenParenStartSignatureSession() { if (_activeSession != null) { _activeSession.Dismiss(); } if (_sigHelpSession != null) { _sigHelpSession.Dismiss(); } TriggerSignatureHelp(); }
bool Cancel() { if (_currentSession == null) { return(false); } _currentSession.Dismiss(); memberCompletion = false; return(true); }
void Caret_PositionChanged(object?sender, CaretPositionChangedEventArgs e) { if (e.NewPosition.VirtualSpaces > 0) { completionSession.Dismiss(); } else { var pos = e.NewPosition.BufferPosition; var span = completionSession.SelectedCompletionSet?.ApplicableTo.GetSpan(pos.Snapshot); if (span is null || pos < minimumCaretPosition || pos < span.Value.Start || pos > span.Value.End) { completionSession.Dismiss(); }
private bool CancelSession() { // if we handled the command, still let it // be handled by the next handler. // This is useful with VsVim, so that pressing esc // to cancel completion can drop you back to // normal mode if (session != null) { session.Dismiss(); return(sessionStartedByCommand); } return(false); }
public bool IsCompletionCommitted(uint key, char inputCharacter) { if (!(key.IsACommitCharacter(inputCharacter) && IsSparkOnlySessionActive())) { return(false); } if (_sparkOnlySession.SelectedCompletionSet.SelectionStatus.IsSelected) { _sparkOnlySession.Commit(); return(true); } _sparkOnlySession.Dismiss(); return(false); }
bool IIntellisenseCommandTarget.ExecuteKeyboardCommand(IntellisenseKeyboardCommand command) { switch (command) { case IntellisenseKeyboardCommand.Up: MoveUpDown(true); return(true); case IntellisenseKeyboardCommand.Down: MoveUpDown(false); return(true); case IntellisenseKeyboardCommand.PageUp: PageUpDown(true); return(true); case IntellisenseKeyboardCommand.PageDown: PageUpDown(false); return(true); case IntellisenseKeyboardCommand.Escape: session.Dismiss(); return(true); case IntellisenseKeyboardCommand.Enter: if (session.SelectedCompletionSet?.SelectionStatus.IsSelected == true) { session.Commit(); return(true); } return(false); case IntellisenseKeyboardCommand.TopLine: WpfUtils.ScrollToTop(control.completionsListBox); return(true); case IntellisenseKeyboardCommand.BottomLine: WpfUtils.ScrollToBottom(control.completionsListBox); return(true); case IntellisenseKeyboardCommand.Home: case IntellisenseKeyboardCommand.End: case IntellisenseKeyboardCommand.IncreaseFilterLevel: case IntellisenseKeyboardCommand.DecreaseFilterLevel: default: return(false); } }
protected bool CommitAutoComplete(bool force) { if (!IsAutoCompleteSessionActive) { return(false); } if (!currentAutoCompleteSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force) { currentAutoCompleteSession.Dismiss(); return(false); } currentAutoCompleteSession.Commit(); return(true); }
private void Filter() { if (_currentSession == null || _currentSession.SelectedCompletionSet == null) { return; } _currentSession.Dismiss(); _currentSession = null; StartSession(); if (_currentSession != null) { _currentSession.Filter(); } }
public void Dismiss() { AssertIsForeground(); _isDismissed = true; if (_editorSessionOpt == null) { // No editor session, nothing to do here. return; } // Slimy bit of nastiness: When we dismiss the presenter session, that will // inadvertantly trigger a LostAggregateFocus event for the view. The reason for this // is long and ugly, but essentially when the completion presenter gets keyboard // focus, it posts a message to surrender focus to the view. However, if the we're // stopping the model computation because the presenter was double-clicked, that // message is still sitting in the queue. Then, when the session is dimissed below // a LostAggregateFocus event gets triggered when the presenter's space reservation // manager is popped off the stack. To work around this, we set focus back to the // view here. Keyboard.Focus(((IWpfTextView)_textView).VisualElement); _editorSessionOpt.Dismiss(); _editorSessionOpt = null; }
public bool Complete(bool force) { if (!IsActive || _currentSession.SelectedCompletionSet == null) { return(false); } if (!_currentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force) { _currentSession.Dismiss(); return(false); } _currentSession.Commit(); return(true); }
public bool TryComplete(char typedChar, uint commandId, ICompletionBroker completionBroker, bool isRecursiveCall = false) { if (IsSessionStartSequence(typedChar)) { bool waitForCompilation; if (ShouldStartSession(typedChar, _document.FilePath, _textView.Caret.Position.BufferPosition, isRecursiveCall, out waitForCompilation)) { TriggerCompletion(completionBroker); } else if (waitForCompilation && !isRecursiveCall) { _compilerService.Compilations .Take(1) .ObserveOn(SynchronizationContext.Current) .Subscribe(_ => TryComplete(typedChar, commandId, completionBroker, true)); } else { if (IsSessionAlive) { _session.Filter(); } } return(true); } var session = _session; if (IsDeletion(commandId) && session != null) { var applicableTo = session.SelectedCompletionSet?.ApplicableTo; if (applicableTo != null) { var text = applicableTo.GetText(applicableTo.TextBuffer.CurrentSnapshot); if (string.IsNullOrWhiteSpace(text)) { session.Dismiss(); } else if (!session.IsDismissed) { session.Filter(); } } return(true); } if (IsSessionAlive) { var applicableTo = _session?.SelectedCompletionSet?.ApplicableTo; if (applicableTo != null && applicableTo.GetSpan(_textView.TextSnapshot).IsEmpty) { _session.Dismiss(); } } return(false); }
private void OpenParenStartSignatureSession() { if (_activeSession != null) { // TODO: Should we complete here instead? _activeSession.Dismiss(); } SnapshotPoint?caretPoint = GetCaretPoint(); if (_sigHelpSession != null) { _sigHelpSession.Dismiss(); } TriggerSignatureHelp(); }
/// <summary> /// Narrow down the list of options as the user types input /// </summary> private void Filter() { if (_currentSession == null) { return; } if (TextView.Caret.Position.BufferPosition <= showPost) { showPost = 0; _currentSession.Dismiss(); return; } _currentSession.SelectedCompletionSet.SelectBestMatch(); _currentSession.SelectedCompletionSet.Recalculate(); }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { var handled = false; var hresult = VSConstants.S_OK; if (pguidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID) nCmdID) { case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: case VSConstants.VSStd2KCmdID.COMPLETEWORD: handled = true; if (IsSessionStarted) break; _currentSession = StartSession(); break; case VSConstants.VSStd2KCmdID.RETURN: if (!IsSessionStarted) break; handled = true; _currentSession.Commit(); break; case VSConstants.VSStd2KCmdID.TAB: if (!IsSessionStarted) break; handled = true; _currentSession.Commit(); break; case VSConstants.VSStd2KCmdID.CANCEL: if (!IsSessionStarted) break; handled = true; _currentSession.Dismiss(); break; } } if (!handled) hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); if (ErrorHandler.Succeeded(hresult)) { if (pguidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID) nCmdID) { case VSConstants.VSStd2KCmdID.TYPECHAR: if (IsSessionStarted) _currentSession.Filter(); break; case VSConstants.VSStd2KCmdID.BACKSPACE: if (IsSessionStarted) { _currentSession.Dismiss(); _currentSession = StartSession(); } break; } } } return hresult; }
public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) { // read XML up to the cursor var point = session.TextView.Caret.Position.BufferPosition; var info = XmlParser.Read(buffer.CurrentSnapshot.GetText(0, point.Position)); if (info.Mode == CompletionMode.Class) { var prevPoint = point - 1; var prevCh = prevPoint.GetChar(); if (prevCh != '<' && prevCh != '.') { session.Dismiss(); return; } } var nodes = info.Nodes; var ns = nodes.SelectMany(r => r.Namespaces ?? Enumerable.Empty<CompletionNamespace>()); var path = nodes.Where(r => r.Mode == CompletionMode.Class).Select(r => r.Name).ToList(); var last = nodes.LastOrDefault(); // get available completion items var items = Designer.Completion.Completion.GetCompletionItems(ns, info.Mode, path, last); // translate to VS completions var completionList = new List<mvli.Completion>(); foreach (var cls in items.OrderBy(r => r.Name)) { completionList.Add(new mvli.Completion(cls.Name, cls.Name, cls.Description, GetGlyph(cls.Type), null)); } completionSets.Insert(0, new CompletionSet( "Eto", "Eto", FindTokenSpanAtPosition(session.GetTriggerPoint(buffer), session, info.Mode), completionList, null)); return; }
//private ITrackingSpan FindTokenSpanAtPosition(ITrackingPoint trackingPoint, ICompletionSession newSession) //{ // SnapshotPoint currentPoint = (newSession.TextView.Caret.Position.BufferPosition); // ITextStructureNavigator navigator = Provider.NavigatorService.GetTextStructureNavigator(TextBuffer); // TextExtent extent = navigator.GetExtentOfWord(currentPoint); // return currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive); //} public void Commit(ICompletionSession session, char typedChar) { if (session.SelectedCompletionSet != null && session.SelectedCompletionSet.SelectionStatus != null) { var completion = session.SelectedCompletionSet.SelectionStatus.Completion; var trackingSpan = completion.Properties.GetProperty<ITrackingSpan>(typeof(ITrackingSpan)); var edit = TextBuffer.CreateEdit(); edit.Replace(trackingSpan.GetSpan(edit.Snapshot), completion.InsertionText); edit.Apply(); } session.Dismiss(); }
public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) { var tokens = classifier.Tokens; if (tokens != null) { // find current token var cursorPosition = session.TextView.Caret.Position.BufferPosition; var currentToken = tokens.FirstOrDefault(t => t.StartPosition <= cursorPosition && t.StartPosition + t.Length >= cursorPosition); if (currentToken != null) { // prepare the context var items = Enumerable.Empty<SimpleRwHtmlCompletion>(); var context = GetCompletionContext(); context.CurrentTokenIndex = classifier.Tokens.IndexOf(currentToken); context.CurrentNode = parser.Root.FindNodeByPosition(session.TextView.Caret.Position.BufferPosition.Position - 1); var combineWithHtmlCompletions = false; TriggerPoint triggerPoint = TriggerPoint.None; if (currentToken.Type == RwHtmlTokenType.DirectiveStart) { // directive name completion triggerPoint = TriggerPoint.DirectiveName; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); } else if (currentToken.Type == RwHtmlTokenType.WhiteSpace) { if (context.CurrentNode is RwHtmlDirectiveNode && context.CurrentTokenIndex >= 2 && tokens[context.CurrentTokenIndex - 2].Type == RwHtmlTokenType.DirectiveStart) { // directive value triggerPoint = TriggerPoint.DirectiveValue; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); } else if (context.CurrentNode is RwHtmlElementNode || context.CurrentNode is RwHtmlAttributeNode) { // attribute name triggerPoint = TriggerPoint.TagAttributeName; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); combineWithHtmlCompletions = sourceProvider.CompletionProviders.OfType<MainTagAttributeNameCompletionProvider>().Single().CombineWithHtmlCompletions; } } else if (currentToken.Type == RwHtmlTokenType.OpenTag) { // element name triggerPoint = TriggerPoint.TagName; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); combineWithHtmlCompletions = true; } else if (currentToken.Type == RwHtmlTokenType.SingleQuote || currentToken.Type == RwHtmlTokenType.DoubleQuote || currentToken.Type == RwHtmlTokenType.Equals) { // attribute value triggerPoint = TriggerPoint.TagAttributeValue; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); combineWithHtmlCompletions = true; } else if (currentToken.Type == RwHtmlTokenType.OpenBinding) { // binding name triggerPoint = TriggerPoint.BindingName; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); } else if (currentToken.Type == RwHtmlTokenType.Colon) { if (context.CurrentNode is RwHtmlBindingNode) { // binding value triggerPoint = TriggerPoint.BindingValue; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); } else { // element name triggerPoint = TriggerPoint.TagName; items = sourceProvider.CompletionProviders.Where(p => p.TriggerPoint == triggerPoint).SelectMany(p => p.GetItems(context)); combineWithHtmlCompletions = true; } } var results = items.OrderBy(v => v.DisplayText).Distinct(CompletionEqualityComparer.Instance).ToList(); // show the session if (!results.Any()) { session.Dismiss(); } else { // handle duplicate sessions (sometimes this method is called twice (e.g. when space key is pressed) so we need to make sure that we'll display only one session lock (activeSessions) { if (activeSessions.Count > 0) { session.Dismiss(); return; } activeSessions.Add(session); session.Dismissed += (s, a) => { lock (activeSessions) { activeSessions.Remove((ICompletionSession)s); } }; session.Committed += (s, a) => { lock (activeSessions) { activeSessions.Remove((ICompletionSession)s); } }; } // show the session var newCompletionSet = new CustomCompletionSet("HTML", "HTML", FindTokenSpanAtPosition(session), results, null); if (combineWithHtmlCompletions && completionSets.Any()) { newCompletionSet = MergeCompletionSets(completionSets, newCompletionSet); } else { completionSets.Clear(); } completionSets.Add(newCompletionSet); } } } }