Current selection

From Apache OpenOffice Wiki
Jump to: navigation, search

Current Selection in Text Documents

Also see Extensions_development_basic.

Having made sure that text is selected, it is common to create a loop to do something to all the currently selected text. But, remember that the first element of the array is either the current selection when there is only one selection, or the insertion point when there is more than one selection. Thus, the following common code:

oCurSelection = thisComponent.getCurrentSelection()
if oCurSelection.supportsService("com.sun.star.text.TextRanges") then
   nCount = oCurSelection.Count
   if nCount = 1 then
      oTextRange = oCurSelection.getByIndex(0)
      'Do some action on oTextRange
   else
      for i = 0 to nCount - 1
         oTextRange = oCurSelection.getByIndex(i)
         'Do some action on oTextRange
      next
   end if
end if
Personal tools