# Highlight current paragraph in Writer?

I would like to highlight current paragraph in writer. To be precise, I would like to highlight the current paragraph with a different background color before and after the cursor.

I am translating a document by simply translating a sentence and then deleting it, and it can be hard to quickly come back to where I am in the midst of a wall of text when I look up from my pecking on the keyboard, looking at another doc, etc.

This may very well be kind of difficult, so any partial solution (like highlighting the entire paragraph or the current sentence) is most welcome!

Using LO 4.4.12 on windows 8.1.

edit retag close merge delete

Sort by » oldest newest most voted

As there isn't a property "BckColour" for paragraphs, and character styles may be used for different purposes, I would suggest to use a font coulour for your distinction. You may define two paragraph styles, derived from 'Text Body' e.g. with different text colour for the translated part and for the original text. Having completed the translation for a paragraph simply apply the "translated" style to it. Headers shouldn't be a problem. Using named styles there are many alternatives with resptect to the details. See attached. Use the 'Styles anf Formatting' tool (F11) with 'Applied paragraph styles' to see what's going on.ask47913TranslatedFrontier001.odt

more

Thanks for the reply. I am pretty familiar with styles and formatting. I am really looking for something automatic like you find in notepad++ or other text editors for coding.

( 2015-03-02 15:04:37 +0200 )edit

Seems I only can tell you how I do it, then. Coming back to an extensive text not willing to search for the cursor, I simply hit Shift+UpArrow and Shuft+DownArrow subsequently - and my eyes have caught the position. This working in nearly every editor (including this forum's and Notepad++)..

( 2015-03-02 15:24:07 +0200 )edit

Hello @sgc,

Here’s a method that can highlight ( and unhighlight ) the current paragraph, sentence, and/or word in different colors before and after the cursor:

NB. These highlight colors are set as character background colors ( CharBackColor ) for the different parts of the paragraph, and will remain coloured until you explicitly remove them again.

Sub Writer_HighlightCurrent( iType As Integer, bHighLight As Boolean )
REM Highlights or UnHighlights the current Paragraph, Sentence, and/or Word.
REM Different colors can be specified for each part to be highlighted before and after the cursor ( see Constants below ).
REM <iType> : Integer specifying which parts to Highlight or UnHighlight:
REM           1 = Paragraph ; 2 = Sentence ; 3 = Paragraph & Sentence ; 4 = Word ; 5 = Paragraph & Word ; 6 = Sentence & Word ; 7 = Paragraph & Sentence & Word.
REM <bHighLight> : Boolean indicating whether to set or remove the Highlight for the specified parts.

REM ****   Put here the desired colors for the different parts to be highlighted:
Const lParagraphHighlightColorBeforeCursor As Long = &HCCC430
Const lSentenceHighlightColorBeforeCursor  As Long = &HDFD400
Const lWordHighlightColorBeforeCursor      As Long = &HFFD0AA
Const lWordHighlightColorAfterCursor       As Long = &HFFE0BA
Const lSentenceHighlightColorAfterCursor   As Long = &HFFF200
Const lParagraphHighlightColorAfterCursor  As Long = &HFFF870

Dim oDoc As Object        : oDoc = ThisComponent
Dim oSel As Object        : oSel = oDoc.CurrentSelection.getByIndex(0)
Dim oViewCursor As Object : oViewCursor = oDoc.CurrentController.getViewCursor()
Dim oTextCursor As Object : oTextCursor = oViewCursor.Text.createTextCursor()

If iType And 1 = 1 Then                    REM Paragraph
oTextCursor.gotoRange ( oSel, False )
oTextCursor.gotoStartOfParagraph( bHighLight )
If bHighLight Then oTextCursor.CharBackColor = lParagraphHighlightColorBeforeCursor
oTextCursor.gotoEndOfParagraph( True )
If Not bHighLight Then oTextCursor.CharBackTransparent = True
If bHighLight Then oTextCursor.CharBackColor = lParagraphHighlightColorAfterCursor
End If
If iType And 2 = 2 Then                    REM Sentence
oTextCursor.gotoRange ( oSel, False )
oTextCursor.gotoStartOfSentence( bHighLight )
If bHighLight Then oTextCursor.CharBackColor = lSentenceHighlightColorBeforeCursor
oTextCursor.gotoEndOfSentence( True )
If Not bHighLight Then oTextCursor.CharBackTransparent = True
If bHighLight Then oTextCursor.CharBackColor = lSentenceHighlightColorAfterCursor
End If
If iType And 4 = 4 Then                    REM Word
oTextCursor.gotoRange ( oSel, False )
oTextCursor.gotoStartOfWord( bHighLight )
If bHighLight Then oTextCursor.CharBackColor = lWordHighlightColorBeforeCursor
oTextCursor.gotoEndOfWord( True )
If Not bHighLight Then oTextCursor.CharBackTransparent = True
If bHighLight Then oTextCursor.CharBackColor = lWordHighlightColorAfterCursor
End If
End Sub


HTH, lib

more

Hi - I suggest you use the Track Changes

1. Tools> Options> Writer> Changes> Deletions> Attributes: select "Background color", then choose your color.
2. Edit> Changes> Record (to enable the feature)
3. Edit> Changes> Accept or Reject (to open the dialog)

It remains you to select the sentence to be translated and press the Delete key. The text is displayed in the color selected in step 1.

When you have finished the translation just click Accept All in the dialog to actually delete the sentence.

more

I think I will write a script in autohotkey to select a sentence and apply a style when I delete the one I have just translated.

triple click::
send {Click 3}
send {backspace}
send {Click 3}
send hotKeyBoundToStyle
send {back}
return


Easy enough but I was hoping LO was more easily customizable beyond the features available via the UI.

more