Difference between revisions of "Current selection"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
Line 13: Line 13:
 
       'Do some action on oTextRange
 
       'Do some action on oTextRange
 
   else
 
   else
       for i = 1 to nCount - 1
+
       for i = 0 to nCount - 1
 
         oTextRange = oCurSelection.getByIndex(i)
 
         oTextRange = oCurSelection.getByIndex(i)
 
         'Do some action on oTextRange
 
         'Do some action on oTextRange

Revision as of 13:36, 29 September 2006

Current Selection in Text Documents

Also see Getting started.

Having made sure that text is selected, it is common to create a loop to do something to all of 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:

[oobas] 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