Recent

Author Topic: [SynEdit] How to get start and end line number of selection  (Read 10896 times)

mrBrown

  • New Member
  • *
  • Posts: 15
[SynEdit] How to get start and end line number of selection
« on: December 17, 2009, 08:58:43 am »
I'm using a SynEdit control to edit input scripts for an mechanical engineering application.

I want to give users the possibility to quickly (un)comment code lines by selecting a number of lines of code and clicking an (un)comment button.

I would like to do something like this:
for line := LineStart to LineEnd do SynEdit1.Lines[line] := '% ' + SynEdit1.Lines[line];

The problem is that I can not find the line numbers where the selection starts end ends.
SynEdit1.SelStart / End only gives me an index, which I don't know how to convert to a line number.

Anyone got an idea?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: [SynEdit] How to get start and end line number of selection
« Reply #1 on: December 17, 2009, 10:06:21 am »
CaretX, CaretY?

mrBrown

  • New Member
  • *
  • Posts: 15
Re: [SynEdit] How to get start and end line number of selection
« Reply #2 on: December 17, 2009, 01:21:00 pm »
CaretX, CaretY give the position of the caret.

What I'm looking for are the start en end line of the selected text.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
Re: [SynEdit] How to get start and end line number of selection
« Reply #3 on: December 17, 2009, 02:46:00 pm »
CaretX, CaretY give the position of the caret.

Ah, sorry. I misunderstood the question.

But I don't know the answer to your question either.
What to do?
Look at the Synedit sources?

Hmm, lets search for SetSelStart.....ah interesting there is a

Blockbegin.X
Blockend.X

Hmmm.... ;-)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12297
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] How to get start and end line number of selection
« Reply #4 on: December 17, 2009, 04:03:05 pm »
Blockbegin.Y
Blockend.Y

are what you are looking for. Blockbegin is always the lower line number (or lower X, if the selection has one line only). They are sorted, if the selection was done "backward" (eg with shift cursor-up)

If Blockend.X=1, then you want to reduce BlockEnd.Y by 1. Because there are 0 chars selected in the last line. It simply means that the whole line above is selected (including carriage-return).

You may want to check SelectionMode too, if block or line mode selection need different treatment.


mrBrown

  • New Member
  • *
  • Posts: 15
Re: [SynEdit] How to get start and end line number of selection
« Reply #5 on: December 18, 2009, 04:09:31 pm »
excellent!

somehow I didn't get from selection to "block" myself...

thanks for the help

 

TinyPortal © 2005-2018