• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Insert text at end of Textview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert text at end of Textview


  • Subject: Re: Insert text at end of Textview
  • From: Scott Anguish <email@hidden>
  • Date: Fri, 4 Oct 2002 01:08:06 -0700

On Friday, October 4, 2002, at 12:59 AM, Alexander Griekspoor wrote:

> Hi Arthurm, Dan & Scott,
>
> Thanks for the helpful reactions! I ended up using the suggestion of
> Arthur.
>> unsigned maxValue = [[textview textStorage] length] - 1;
>> [textview setSelectedRange:NSMakeRange(maxValue, 0)];
>> [textview insertText: @"blabla"];
>
>
This will (obviously) change the current selection, which could be
annoying to a user if they've set it for themselves.


> Still, life would be easier if Apple could extend the textview class
> with the method
> insertTextAtEnd or something like that...
>

Add a category to NSTextView.. write it once, stick it in a
file/framework and continue to use it

> Again, thank you all for helping me out!
> Alex
>
>
>>
>> On donderdag, okt 3, 2002, at 14:50 Europe/Amsterdam, Alexander
>> Griekspoor wrote:
>>
>>> Hello all,
>>>
>>> I've tried to search the archives, but couldn't find an answer to the
>>> following question:
>>> How do I make sure that my text is inserted at the end of the
>>> contents
>>> of my textview?
>>> I now how to make my textview first responder, and how to insert the
>>> text with
>>> [myTextView insertText: @"blabla"];
>>> I guess I have to set the selection first with:
>>> [myTextView setSelectedRange: NSMakeRange(X,Y)]; where X marks the
>>> last
>>> position in the text, and Y the length (guess it should be 0 in my
>>> case). The problem is, how do I find out what the last character
>>> position is in my textview.
>>
>>
>> unsigned maxValue = [[textview textStorage] length] - 1;
>> [textview setSelectedRange:NSMakeRange(maxValue, 0)];
>> [textview insertText: @"blabla"];
>>
>> Arthur Clemens
>>
>
>
>> I use (in perl, so this is a bit of a back translation):
>>
>> [[myTextView textStorage] appendAttributedString: @"blahblah"];
>>
>> but there's probably a good reason to not do that.
>> --
>> Dan
>
>
>> I covered just this situation in my talk at O'Reilly yesterday...
>>
>> if you're using plain text, then do this
>>
>> NSRange insertAtEnd=NSMakeRange([[theTextView textStorage] length],0);
>> [theTextView replaceCharactersInRange:insertAtEnd withString:@"new
>> string"];
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Insert text at end of Textview (From: Alexander Griekspoor <email@hidden>)

  • Prev by Date: Re: NSTableView and check boxes (for the hundredth time)
  • Next by Date: Re: Bochs - Free PC emulator
  • Previous by thread: Re: Insert text at end of Textview
  • Next by thread: Re: Insert text at end of Textview
  • Index(es):
    • Date
    • Thread