コード例 #1
0
ファイル: AutoCompletion.cs プロジェクト: massreuy/3P
        /// <summary>
        /// Call this method to insert the completionItem at the given offset in regards to the current caret position
        /// (it will replace the word found at CaretPosition + Offset by the completionItem.DisplayText)
        /// </summary>
        private static void InsertSuggestion(CompletionItem data, int offset = 0)
        {
            try {
                if (data != null)
                {
                    // in case of keyword, replace abbreviation if needed
                    var replacementText = data.DisplayText;
                    if (Config.Instance.AutoCompleteReplaceAbbreviations && data.Flags.HasFlag(ParseFlag.Abbreviation))
                    {
                        var fullKeyword = Keywords.Instance.GetFullKeyword(data.DisplayText).ConvertCase(Config.Instance.AutoCompleteKeywordCaseMode);
                        replacementText = fullKeyword ?? data.DisplayText;
                    }

                    _insertingWord           = true;
                    _positionOfLastInsertion = Sci.ReplaceWordWrapped(replacementText, _additionalWordChar, offset);
                    _insertingWord           = false;

                    // Remember this item to show it higher in the list later
                    RememberUseOf(data);

                    if (data is SnippetCompletionItem)
                    {
                        Snippets.TriggerCodeSnippetInsertion();
                    }

                    Cloak();
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error during InsertSuggestion");
            }
        }
コード例 #2
0
ファイル: Snippets.cs プロジェクト: zhitian/3P
        public static void PrepareForIncertion(string rawText, int charsOffset, int documentOffset = 0)
        {
            LocSnippetContext = new SnippetContext();

            LocSnippetContext.ReplacementString = rawText;

            string offset = new string(' ', charsOffset);

            LocSnippetContext.ReplacementString = LocSnippetContext.ReplacementString.Replace(Environment.NewLine, Environment.NewLine + offset);

            int endPos;
            int startPos = LocSnippetContext.ReplacementString.IndexOf("$", StringComparison.Ordinal);

            while (startPos != -1)
            {
                endPos = LocSnippetContext.ReplacementString.IndexOf("$", startPos + 1, StringComparison.Ordinal);

                if (endPos != -1)
                {
                    //'$item$' -> 'item'
                    int newEndPos = endPos - 2;

                    LocSnippetContext.Parameters.Add(new Point(startPos + documentOffset, newEndPos + 1 + documentOffset));

                    string leftText       = LocSnippetContext.ReplacementString.Substring(0, startPos);
                    string rightText      = LocSnippetContext.ReplacementString.Substring(endPos + 1);
                    string placementValue = LocSnippetContext.ReplacementString.Substring(startPos + 1, endPos - startPos - 1);

                    LocSnippetContext.ReplacementString = leftText + placementValue + rightText;

                    endPos = newEndPos;
                }
                else
                {
                    break;
                }

                startPos = LocSnippetContext.ReplacementString.IndexOf("$", endPos + 1, StringComparison.Ordinal);
            }

            Sci.ReplaceWordWrapped(LocSnippetContext.ReplacementString, null, -1);

            if (LocSnippetContext.Parameters.Any())
            {
                LocSnippetContext.CurrentParameter = LocSnippetContext.Parameters.FirstOrDefault();
            }
        }