Esempio n. 1
0
 /// <summary>
 /// Called before character type is passed down to the core editor
 /// along the controll chain. Gives language-specific controller
 /// a chance to initiate different action and potentially 'eat'
 /// the character. For example, in R typing 'abc[TAB] should bring
 /// up intellisense list rather than actually insert the tab character.
 /// </summary>
 /// <returns>
 /// True if character was handled and should not be
 /// passed down to core editor or false otherwise.
 /// </returns>
 public override bool OnPreTypeChar(char typedCharacter)
 {
     // Allow tab to bring intellisense if
     //  a) REditorSettings.ShowCompletionOnTab true
     //  b) Position is at the end of a string so we bring completion for files
     //  c) There is no selection
     if (typedCharacter == '\t' && !HasActiveCompletionSession && TextView.Selection.StreamSelectionSpan.Length == 0)
     {
         // if previous character is identifier character, bring completion list
         SnapshotPoint?position = REditorDocument.MapCaretPositionFromView(TextView);
         if (position.HasValue)
         {
             int pos = position.Value;
             if (pos > 0 && pos <= position.Value.Snapshot.Length)
             {
                 bool endOfIdentifier = RTokenizer.IsIdentifierCharacter(position.Value.Snapshot[pos - 1]);
                 bool showCompletion  = endOfIdentifier && REditorSettings.ShowCompletionOnTab;
                 if (!showCompletion)
                 {
                     var    document = REditorDocument.FromTextBuffer(position.Value.Snapshot.TextBuffer);
                     string directory;
                     showCompletion = RCompletionEngine.CanShowFileCompletion(document.EditorTree.AstRoot, pos, out directory);
                 }
                 if (showCompletion)
                 {
                     ShowCompletion(autoShownCompletion: false);
                     return(true); // eat the character
                 }
             }
         }
     }
     return(base.OnPreTypeChar(typedCharacter));
 }
Esempio n. 2
0
        /// <summary>
        /// Called before character type is passed down to the core editor
        /// along the controll chain. Gives language-specific controller
        /// a chance to initiate different action and potentially 'eat'
        /// the character. For example, in R typing 'abc[TAB] should bring
        /// up intellisense list rather than actually insert the tab character.
        /// </summary>
        /// <returns>
        /// True if character was handled and should not be
        /// passed down to core editor or false otherwise.
        /// </returns>
        public override bool OnPreTypeChar(char typedCharacter)
        {
            // Allow tab to bring intellisense if
            //  a) REditorSettings.ShowCompletionOnTab true
            //  b) Position is at the end of a string so we bring completion for files
            //  c) There is no selection
            if (typedCharacter == '\t' && !HasActiveCompletionSession && TextView.Selection.StreamSelectionSpan.Length == 0)
            {
                // if previous character is identifier character, bring completion list
                var position = TextView.GetCaretPosition(_textBuffer);
                if (position.HasValue)
                {
                    int pos      = position.Value;
                    var document = position.Value.Snapshot.TextBuffer.GetEditorDocument <IREditorDocument>();
                    if (!document.IsPositionInComment(pos))
                    {
                        if (pos > 0 && pos <= position.Value.Snapshot.Length)
                        {
                            var endOfIdentifier = RTokenizer.IsIdentifierCharacter(position.Value.Snapshot[pos - 1]);
                            var showCompletion  = endOfIdentifier && _settings.ShowCompletionOnTab;
                            if (!showCompletion)
                            {
                                showCompletion = RCompletionEngine.CanShowFileCompletion(document.EditorTree.AstRoot, pos, out string directory);
                            }
                            if (showCompletion)
                            {
                                ShowCompletion(autoShownCompletion: false);
                                return(true); // eat the character
                            }
                        }
                    }
                }
            }
            else if (typedCharacter == '#')
            {
                if (TryInsertRoxygenBlock())
                {
                    return(true);
                }
            }

            return(base.OnPreTypeChar(typedCharacter));
        }