Difference between revisions of "Current selection"
From Apache OpenOffice Wiki
(add to cat Basic:Tutorials) |
m |
||
Line 3: | Line 3: | ||
Also see [[Extensions_development_basic]]. | Also see [[Extensions_development_basic]]. | ||
− | Having made sure that text is selected, it is common to create a loop to do something to all | + | 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: |
− | < | + | <syntaxhighlight 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 | ||
− | </ | + | </syntaxhighlight> |
[[Category:Basic:Tutorials]] | [[Category:Basic:Tutorials]] |
Latest revision as of 13:50, 5 March 2021
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