Writer Macro: working with current selection [closed]

asked 2016-06-25 04:34:33 +0200

paul1149 gravatar image

I'm trying to capture the current selection in a Writer doc, then test the end points for spaces. If they are spaces I want to trim the Selection back, until the endpoints are non-spaces.

I got this from OOo's wiki:

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
      for i = 0 to nCount - 1
         oTextRange = oCurSelection.getByIndex(i)
         'Do some action on oTextRange
   end if
end if

The oTextRange variable contains the current Selection in its "String" component.

But I don't have a clue how to go to the end points, test them for "spacehood" and trim them back if necessary.

I have consulted Andrew's book, which unfortunately only makes me more confused. And I didn't see anything online.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2020-09-08 15:55:50.308384


Which of the books Andrew you have in mind? Chapter 7.2. Text Cursors, What Are They?

JohnSUN gravatar imageJohnSUN ( 2016-06-25 05:23:30 +0200 )edit

I don't understand you... if you show an example, I help you with the code

Best regards

mauricio gravatar imagemauricio ( 2016-06-25 05:28:22 +0200 )edit

It seems to me that he wants to collapse each of the selections to Trim(oSel.getString()) - without spaces before and after - and then highlight them (reselect it)

JohnSUN gravatar imageJohnSUN ( 2016-06-25 09:54:30 +0200 )edit