NSTextView selection

  • Hello,

    I have a NSTextView and when I select all the text, all the lines get
    highlighted from left to right margin, except the last line which is
    highlighted from left margin to the last character on line. Please, is it
    possible to highlight the last line in the same way as the other ones are,
    i.e. to highlight it from left to very right?

    I think I need to use "setExtraLineFragmentRect:usedRect:textContainer:" of
    NSLayoutManager but I'm not sure how to proceed and if it's even the right
    way of doing this.

    Thanks in advance,

    Ecir Hana
  • On Jun 4, 2012, at 10:10 AM, ecir hana wrote:

    > Hello,
    >
    > I have a NSTextView and when I select all the text, all the lines get
    > highlighted from left to right margin, except the last line which is
    > highlighted from left margin to the last character on line. Please, is it
    > possible to highlight the last line in the same way as the other ones are,
    > i.e. to highlight it from left to very right?

    Erm, why do you want this? The point is to show that your selection encompasses a newline character.

    --Kyle Sluder
  • You can use an NSTextView delegate and NSFormatters to adjust the selection as it is being made.

    On Jun 4, 2012, at 1:10 PM, ecir hana wrote:

    > Hello,
    >
    > I have a NSTextView and when I select all the text, all the lines get
    > highlighted from left to right margin, except the last line which is
    > highlighted from left margin to the last character on line. Please, is it
    > possible to highlight the last line in the same way as the other ones are,
    > i.e. to highlight it from left to very right?
    >
    > I think I need to use "setExtraLineFragmentRect:usedRect:textContainer:" of
    > NSLayoutManager but I'm not sure how to proceed and if it's even the right
    > way of doing this.
    >
    > Thanks in advance,
    >
    > Ecir Hana

    Charlie Dickman
    <3tothe4th...>
  • On Jun 4, 2012, at 10:10 AM, ecir hana wrote:

    > I have a NSTextView and when I select all the text, all the lines get
    > highlighted from left to right margin, except the last line which is
    > highlighted from left margin to the last character on line. Please, is it
    > possible to highlight the last line in the same way as the other ones are,
    > i.e. to highlight it from left to very right?

    Add a newline to the end of the text.

    —Jens
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today