Difference between revisions of "Current selection"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Fixed link)
m (code> -> source>)
Line 5: Line 5:
 
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:  
 
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:  
  
<code>[oobas]
+
<source lang=oobas>
 
oCurSelection = thisComponent.getCurrentSelection()
 
oCurSelection = thisComponent.getCurrentSelection()
 
if oCurSelection.supportsService("com.sun.star.text.TextRanges") then
 
if oCurSelection.supportsService("com.sun.star.text.TextRanges") then
Line 19: Line 19:
 
   end if
 
   end if
 
end if
 
end if
</code>
+
</source>

Revision as of 01:44, 14 March 2009

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 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:

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