• 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: NSTextView Text Dragging Position (2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView Text Dragging Position (2)


  • Subject: Re: NSTextView Text Dragging Position (2)
  • From: Satoshi Matsumoto <email@hidden>
  • Date: Fri, 14 Oct 2005 10:19:04 +0900

on 05.10.14 5:38 AM, Seth Willits at email@hidden wrote:
> Does anyone know how to determine the character positions that text
> was dropped onto an NSTextView? I need to manipulate the string and
> do my own custom insertion but I haven't yet figured out how to find
> the character position to insert the text at.

You can get the dragging character location from  NSDraggingInfo.

For example,

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{

    NSPoint draggingLocation = [sender draggingLocation];
    draggingLocation = [self convertPoint:draggingLocation fromView:nil];
   unsigned int characterIndex = [self
characterIndexOfPoint:draggingLocation];
    ......

}

- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint
{
unsigned int glyphIndex;
NSLayoutManager *layoutManager = [self layoutManager];
float fraction;
NSRange range;

    range = [layoutManager glyphRangeForTextContainer:[self textContainer]];
    glyphIndex = [layoutManager glyphIndexForPoint:aPoint
inTextContainer:[self textContainer]
fractionOfDistanceThroughGlyph:&fraction];
    if( fraction > 0.5 ) glyphIndex++;

    if( glyphIndex == NSMaxRange(range) ) return  [[self textStorage]
length];
    else return [layoutManager characterIndexForGlyphAtIndex:glyphIndex];

}



Satoshi


-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTextView Text Dragging Position (2)
      • From: Seth Willits <email@hidden>
References: 
 >NSTextView Text Dragging Position (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: NSTextView Text Dragging Position
  • Next by Date: Re: +[NSBundle bundleWithIdentifier:]
  • Previous by thread: Re: NSTextView Text Dragging Position
  • Next by thread: Re: NSTextView Text Dragging Position (2)
  • Index(es):
    • Date
    • Thread