[Issue] Display line number, column number in status bar

Discuss the word processor

[Issue] Display line number, column number in status bar

Postby erbsenzahl » Sun Nov 22, 2020 10:27 am

Hello,

in the German forum for LibreOffice (https://www.libreoffice-forum.de/viewto ... =5&t=33002) there is a question unsolved:

Can Writer show the current cursor position as line/column in the status bar like Notepad++ (or Microsoft Word) can do?

Image

Any suggestions?

Thanks for reading, cheers.
Last edited by Hagar Delest on Sun Nov 22, 2020 12:29 pm, edited 1 time in total.
Reason: tagged issue
OpenOffice 4.1.8 on LinuxMint 19 or 20 Mate, rarely W7-64 pro and W10-64 pro; LibreOffice current versions 6 or 7
(author is no native speaker)
erbsenzahl
Volunteer
 
Posts: 163
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Writer: display line number, column number in status bar

Postby Hagar Delest » Sun Nov 22, 2020 12:28 pm

Not yet implemented (nor in LibreOffice): [Issue] Way to view column/row numbers in Writer?
Issue 18004.
LO 6.4.6 on Xubuntu 20.04 and Windows 10.
User avatar
Hagar Delest
Moderator
 
Posts: 29061
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Issue] Display line number, column number in status bar

Postby JeJe » Sun Nov 22, 2020 2:49 pm

You could turn on the line numbering for the line.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1228
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Issue] Display line number, column number in status bar

Postby JeJe » Sun Nov 22, 2020 3:02 pm

A simple but probably tedious to use macro can give the column number in a message box.

CAUTION: may not work/give errors in circumstances such as the cursor not being a normal text one.

Code: Select all   Expand viewCollapse view
Sub GetCursorColumn
on error goto hr
vc = thiscomponent.currentcontroller.viewcursor
vc.gotoStartOfLine(true)
lenst= len(vc.string)
vc.collapsetoend
msgbox "Column: " & lenst
hr:
End Sub


Edit: slight improvement, collapsed selection before showing message box
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1228
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Issue] Display line number, column number in status bar

Postby JeJe » Sun Nov 22, 2020 3:34 pm

Unfortunately the ruler doesn't allow you to have Column marking.

A bit off beat... but if you're using a fixed width (non-proportional) font you can make your own and put it in the header.
Attachments
Heading Character Ruler.odt
(10.92 KiB) Downloaded 1 time
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1228
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Issue] Display line number, column number in status bar

Postby Lupp » Mon Nov 23, 2020 1:31 am

Q&D:
Code: Select all   Expand viewCollapse view
Sub lineAndPosInText(Optional pDoc)
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
If isMissing(pDoc) Then pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
  REM For the BodyText line counting is done per page.
  vc.jumpToStartOfPage()
Else
  REM Otherwise for the current text not regarding pages.
  cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
  LinesAbove = LinesAbove + 1
  vc.goDown(1, False)
Wend
MsgBox("Line:" & LinesAbove + 1 & "; Position in line:" & charsLeft + 1 & Chr(10) & _
       IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
cCtrl.select(oldSel)
End Sub

Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function


We may feel sure there are only simple cases without nested tables or frames or whatever, but we cannot be sure.
That "rare complications" to be expected make reliable solutions rare.
On Windows 10: LibreOffice 7.0 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2936
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Issue] Display line number, column number in status bar

Postby JeJe » Mon Nov 23, 2020 2:44 am

This is Lupp's code slightly modified to add his result to the status bar, wait half a second and return the status bar to normal. You just need a shortcut to run the macro.
Change the 500 number to a different value if you want more time to look at the result.

Code: Select all   Expand viewCollapse view
Sub lineAndPosInText2()
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
'If isMissing(pDoc) Then

pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
  REM For the BodyText line counting is done per page.
  vc.jumpToStartOfPage()
Else
  REM Otherwise for the current text not regarding pages.
  cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
  LinesAbove = LinesAbove + 1
  vc.goDown(1, False)
Wend
cCtrl.select(oldSel)

lbl = ( "Line:" & LinesAbove + 1 & "; Position in line:" & charsLeft + 1 & Chr(10) & _
       IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
   sbar = pdoc.getCurrentController.StatusIndicator 'add to the status ar
   sbar.start( lbl,0 )
    Wait 500 'wait a bit so you can look at it CHANGE 500 TO PREFERRED TIME 500 = HALF A SECOND 1000 = 1 SECOND
   sbar.end()

End Sub

Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function


Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1228
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Issue] Display line number, column number in status bar

Postby JeJe » Mon Nov 23, 2020 3:31 pm

I need a second to read it, and it helps if its abbreviated a little.

Code: Select all   Expand viewCollapse view
Sub lineAndPosInText2()
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
'If isMissing(pDoc) Then

pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
  REM For the BodyText line counting is done per page.
  vc.jumpToStartOfPage()
Else
  REM Otherwise for the current text not regarding pages.
  cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
  LinesAbove = LinesAbove + 1
  vc.goDown(1, False)
Wend
cCtrl.select(oldSel)

lbl = ( "Line:" & LinesAbove + 1 & ", Col:" & charsLeft + 1 & Chr(10) & _
       IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
   sbar = pdoc.getCurrentController.StatusIndicator
   sbar.start( lbl,0 )
      Wait 1000
sbar.end()

End Sub

Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function


Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1228
Joined: Wed Mar 09, 2016 2:40 pm


Return to Writer

Who is online

Users browsing this forum: No registered users and 31 guests