private void removeParagraph()
{
bool isTwoLatestSentenceDifferentPara = false; // keeps track if the last two sentences are from different paragraph
Word.Range range = Globals.ThisAddIn.Application.ActiveDocument.Range(extensionRange.End, extensionRange.End);
if (extensionWordPos != -1) // if is extending some words
{
// compare last two sentences
Sentence currentSentence = (Sentence)extensions[extensionPos];
Sentence previousSentence = (Sentence)extensions[extensionPos-1];
if (currentSentence.paragraphID != previousSentence.paragraphID)
isTwoLatestSentenceDifferentPara = true;
// remove extended words from current sentence
for (int i = extensionWordPos; i >= 0; i--)
{
String word = currentExtensionPosWordList[i];
shiftRange(range, new StringInfo(word).LengthInTextElements);
}
// reset variables used for extending word
currentExtensionPosWordList = null;
extensionWordPos = -1;
extensionPos--; // move focus to previous sentence
}
if (!isTwoLatestSentenceDifferentPara)
{
Sentence lastExtendSentence = (Sentence)extensions[extensionPos];
int lastExtendSentenceParaID = lastExtendSentence.paragraphID;
int previousSentenceParaID = -1;
// putting sentence one by one into the range for removal
do
{
shiftRange(range, new StringInfo(((Sentence)extensions[extensionPos]).content).LengthInTextElements);
extensionPos--;
checkAndRemoveParagraphSpace(range);
// retrieve paragraph id of the sentence before
if (extensionPos >= 0)
{
lastExtendSentence = (Sentence)extensions[extensionPos];
previousSentenceParaID = lastExtendSentence.paragraphID;
}
else
break;
} while (lastExtendSentenceParaID == previousSentenceParaID);
}
removeRangeTextAndRepositionCursor(range);
}