ACPAddIn.ThisAddIn.insertSuggestion C# (CSharp) Method

insertSuggestion() public method

public insertSuggestion ( Suggestion suggestion ) : void
suggestion Suggestion
return void
        public void insertSuggestion(Suggestion suggestion)
        {
            // for User Testing
            endReqSuggTime = DateTime.Now;
            appendReqSuggTimeString();

            Word.Range range = currentSelection.Range;

            int characterCount = 0;

            switch (suggestion.type)
            {
                case Suggestion.SENTENCE:
                    // Find out the number of words before last sentence
                    characterCount = getWordsBeforeLastSentence().TrimStart().Count();
                    break;
                case Suggestion.ENTITY:
                    // Replace the last few word(s)
                    characterCount = checkEntityWords((Entity)suggestion);
                    break;
            }

            // Replace the text before last sentence with the choosen suggestion
            range = currentSelection.Range;
            extMode.setExtensionRange(range);
            range.MoveStart(Word.WdUnits.wdCharacter, -characterCount);
            switch (suggestion.type)
            {
                case Suggestion.SENTENCE:
                    range.Text = ((Sentence)suggestion).content + ExtensionMode.extraSpace;
                    break;
                case Suggestion.ENTITY:
                    range.Text = ((Entity)suggestion).content;
                    break;
            }

            // Reposition the cursor to the end of the sentence that is just pasted
            int position = range.End;
            currentSelection.SetRange(position, position);

            // Hide the form
            autoCompleteForm.Hide();

            if (suggestion.type == Suggestion.SENTENCE)
            {
                ExtensionMode.highlight(range);
                extMode.setupExtensionMode(suggestion);

                extendSuggestionForm.updateLocation(applicationLocation, applicationSize);
                extendSuggestionForm.ShowForm();
            }

            // Inform ACP the suggestion that was selected for Ranking purpose.
            logic.chooseSuggestion(suggestion);
        }