How to highlight current line

1,557 views
Skip to first unread message

Rohit Taralekar

unread,
Oct 15, 2013, 5:37:38 AM10/15/13
to scintilla...@googlegroups.com
I have tried following snippet but it is not highlighting the line

scintillaTextEditor.Lines[1].Select();
scintillaTextEditor.Selection.BackColor = Color.Red;


plz help...:-(



Neil Hodgson

unread,
Oct 15, 2013, 4:40:22 PM10/15/13
to scintilla...@googlegroups.com
Rohit Taralekar:

> I have tried following snippet but it is not highlighting the line
>
> scintillaTextEditor.Lines[1].Select();

You are using a wrapper I am unfamiliar with. In basic Scintilla a line is selected by finding its start and end and selecting that range. SCI_POSITIONFROMLINE, SCI_SETSELECTIONSTART, SCI_SETSELECTIONEND.

Neil

CNavarro

unread,
Sep 9, 2015, 9:44:00 AM9/9/15
to scintilla-interest, nyama...@me.com
Good afternoon
I'm doing a wrapper Harbour and want to create a message that allows me to select the current line ( Not highlighting the line )
I am making the following tests but can not get the line is highlighted

 nLine := ::Send( SCI_LINEFROMPOSITION, ::Send( SCI_GETCURRENTPOS, 0, 0 ), 0 )

Test-1

nStart    := ::Send( SCI_POSITIONFROMLINE, nLine , 0 )
nEnd      := ::Send( SCI_GETLINEENDPOSITION, nLine , 0 )
::Send( SCI_SETSELECTIONSTART, nStart, 0 ) 
::Send( SCI_SETSELECTIONEND, nEnd, 0 )

Test - 2

nStart    := ::Send( SCI_POSITIONFROMLINE, nLine , 0 )
nEnd      := ::Send( SCI_GETLINEENDPOSITION, nLine , 0 )
::Send( SCI_SETANCHOR, nStart, 0 )
::Send( SCI_SETCURRENTPOS, nEnd, 0 )

Test - 3

nStart    := ::Send( SCI_POSITIONFROMLINE, nLine , 0 )
nEnd      := ::Send( SCI_GETLINEENDPOSITION, nLine , 0 )
::Send( SCI_SETSEL, nStart, nEnd )

Not highlighting the line

But the command
::Send( SCI_SETSEL, nStart, -1 )
If it works well, and I select from the cursor position to the end of file

Please, I stand with this issue for some time
I forget that?
( Google translator )
Regards

Neil Hodgson

unread,
Sep 9, 2015, 6:06:38 PM9/9/15
to scintilla-interest
CNavarro:

> I am making the following tests but can not get the line is highlighted
>
> nLine := ::Send( SCI_LINEFROMPOSITION, ::Send( SCI_GETCURRENTPOS, 0, 0 ), 0 )


You should print out each variable to check that they are sensible.

Check whether the selection appears after redrawing, perhaps by dragging the window a little larger to force a redraw.

Neil

CNavarro

unread,
Sep 9, 2015, 6:57:40 PM9/9/15
to scintilla-interest, nyama...@me.com
Neil, thanks
I've been doing debug the value of variables and believe is right
I do not see the error
Example:
I am on line 0, position 0, which contains 21 characters

I executed the code for the example is:

nStart    := ::Send( SCI_POSITIONFROMLINE, nLine - 1, 0 )
nEnd      := ::Send( SCI_GETLINEENDPOSITION, nLine - 1, 0 )
::Send( SCI_SETCURRENTPOS, nEnd, 0 )
::Send( SCI_GOTOPOS, nEnd, 0 )
::Send( SCI_SETANCHOR, nStart, 0 )


Values of variables
nStart = 0      nEnd = 21       ::Send( SCI_GETANCHOR, 0, 0 ) = 0        ::Send( SCI_GETSELECTIONSTART, 0, 0 ) = 0        ::Send( SCI_GETSELECTIONEND, 0, 0 ) = 21

But I do not get that the line is highlighted
The window is maximized
Please, 
I just need the correct logic to implement the necessary commands ( see Test of my post previous )
Thanks in advance
Title210.png

Neil Hodgson

unread,
Sep 10, 2015, 2:08:40 AM9/10/15
to scintilla...@googlegroups.com
CNavarro:

> I executed the code for the example is:
>
> nStart := ::Send( SCI_POSITIONFROMLINE, nLine - 1, 0 )

nLine-1 doesn’t look good: the line returned from SCI_LINEFROMPOSITION is 0 based and its simpler if all code treats the first line as line 0.

> ::Send( SCI_GETSELECTIONEND, 0, 0 ) = 21
>
> But I do not get that the line is highlighted

Maybe your background colour or line background is too heavy to see the selection. Turn them off or set selection background to bright red.

Neil

CNavarro

unread,
Sep 10, 2015, 6:01:45 AM9/10/15
to scintilla-interest, nyama...@me.com
Neil
- nLine-1

You're right, but I use the following statement in my program
nLine  := :: GetCurrentLine () + 1
That's not a problem.
I know Scintilla used as first line the value 0

- Colors background 
If I press double click on the line is highlighted
If I use the keyboard (SHIFT + Cursors, SHIFT + End, etc) line is highlighted
If executed by code (SCI_SETSEL, nPos, -1) the text to the end of the document is highlighted well
All previous cases work well with the defined highlighting color
The highlight color is defined at the beginning of the application
// :: Send (SCI_SETSELFORE, 1 CLR_WHITE)
    :: Send (SCI_SETSELBACK, 1, RGB (0, 179, 179))

I'm desperate
I do not know what else I can do tests
Help, please
Thanks 

CNavarro

unread,
Sep 10, 2015, 6:07:20 AM9/10/15
to scintilla-interest, nyama...@me.com
I forgot to mention that the multiple selection is active
::Send( SCI_SETMULTIPLESELECTION, 1, 0 )
Thanks

Neil Hodgson

unread,
Sep 10, 2015, 8:25:37 PM9/10/15
to scintilla...@googlegroups.com
CNavarro:

> I'm desperate
> I do not know what else I can do tests

Is the caret blinking?

Neil

CNavarro

unread,
Sep 11, 2015, 2:16:36 AM9/11/15
to scintilla-interest, nyama...@me.com
Yes
Thanks

Neil Hodgson

unread,
Sep 11, 2015, 3:31:19 AM9/11/15
to scintilla...@googlegroups.com
CNavarro:

> Yes

If the cursor blinks then that means that the line with the caret is being redrawn so its not just needing a display refresh.

Can’t see any reason for the selection not to show.

Neil

CNavarro

unread,
Sep 11, 2015, 4:48:52 AM9/11/15
to scintilla-interest, nyama...@me.com
The cursor is blinking but stays at the beginning of the line
Should not keep the cursor at the end of the line or the beginning of next?
Thanks for your time

CNavarro

unread,
Sep 11, 2015, 2:01:50 PM9/11/15
to scintilla-interest, nyama...@me.com
Neil
Now I understand your comments
My tests and research have taken a different path
I am still far from dominating Scintilla
Thanks for everything

Pd .: Scintilla could add to a message, eg: SCI_SELLINE   :)

Neil Hodgson

unread,
Sep 13, 2015, 9:45:53 PM9/13/15
to scintilla...@googlegroups.com
CNavarro:

> The cursor is blinking but stays at the beginning of the line
> Should not keep the cursor at the end of the line or the beginning of next?

Yes, the caret should be at the end of the line. Something is going badly wrong here but I can’t tell what.

Neil

CNavarro

unread,
Sep 14, 2015, 4:15:07 PM9/14/15
to scintilla-interest, nyama...@me.com
Thanks, Neil
I'm reviewing the code line by line
Sure thanks to him as above to find the problem
Reply all
Reply to author
Forward
0 new messages