Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:09:29+00:00 2026-06-01T15:09:29+00:00

I have a Cocoa, Document-based Mac OS X application. One feature that I have

  • 0

I have a Cocoa, Document-based Mac OS X application.

One feature that I have in my app is a list of text items which can be double-clicked to edit. When the user double-clicks one of the text items, I place the current window’s fieldEditor text field over the clicked text item to allow editing.

Everything is working fine except for one problem. I cannot figure out how to make the fieldEditor text field clip + scroll rather than wrap its text. Here’s what it currently looks like:

enter image description here

See how the text is wrapping to a second line? I don’t want that. I’d like it to remain one line which scrolls (and appears clipped).

Here’s an example of it working correctly on a list item which has less text:

enter image description here

Here’s what I’m trying in my view controller:

NSWindow *win = [listItemView window];
NSText *fieldEditor = [win fieldEditor:YES forObject:listItemView];
[fieldEditor setFont:[TDListItemView titleFont]];
[fieldEditor setAlignment:NSLeftTextAlignment];
[fieldEditor setDrawsBackground:YES];
[fieldEditor setBackgroundColor:[NSColor whiteColor]];
[fieldEditor setString:str];
[fieldEditor setDelegate:self];
[fieldEditor selectAll:nil];

if ([fieldEditor isKindOfClass:[NSTextView class]]) {
    NSTextView *tv = (NSTextView *)fieldEditor;
    NSMutableParagraphStyle *style = [[[tv defaultParagraphStyle] mutableCopy] autorelease];
    [style setLineBreakMode:NSLineBreakByClipping];
    [tv setDefaultParagraphStyle:style];
}

CGRect r = [self fieldEditorRectForBounds:[listItemView bounds] index:idx]; // height here is 10.0
[fieldEditor setFrame:r];
[fieldEditor setNeedsDisplay:YES];
[[self view] addSubview:fieldEditor];
[win makeFirstResponder:fieldEditor];

Notice that part in the middle: I check to see if this fieldEditor is an instance of NSTextView in order to call the setDefaultParagraphStyle: method on it. This is my attempt to get the fieldEditor to clip its text — via the NSLineBreakByClipping value. It’s not having any effect. And I’m not even sure this is what I should be doing to get the fieldEditor to scroll on one line.

Also note that the height of the rect which I compute in my -fieldEditorRectForBounds:index: method is correct, and is providing a rect which is correctly sized for a single line of text (14.0 pixels in this case).

What am I missing to make the fieldEditor display a single line of scrolled/clipped text?


I’ve also tried adding these lines in the middle section:

    [[tv textContainer] setHeightTracksTextView:YES];
    [[tv textContainer] setWidthTracksTextView:YES];

This has the desired effect of resizing the visible portion of the fieldEditor which is good. But the bad news is that it doesn’t change the fact that the text is still wrapped, rather than clipped + scrolled. 🙁


This seems related to this constant:

NSStringDrawingUsesLineFragmentOrigin

which can be used in the options: argument of:

-[NSAttributedString drawWithRect:options:attributes:]

but in my case, I’m working from a NSText field editor, not an NSAttributedString. I can’t figure out how to do this sort of thing with an NSText field editor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:09:31+00:00Added an answer on June 1, 2026 at 3:09 pm

    Hmmm … NSTextView relies on an NSScrollView entirely for its scrolling behavior. I’m not sure if there’s more to this that I’m not seeing, but it looks like the “historic” solution to your problem is either to:

    Use A Different Control

    You can use an editable NSTextField in its standard IB label configuration with editing enabled and scrolling selected as the behavior. It does all the heavy lifting for you already when configured properly – no need to mess around with the field editor directly.

    …or to…

    Cheat

    Slap the field editor into an appropriately-sized and configured NSScrollView (allow only horizontal scroll; don’t show the scrollers) dynamically, then remove the scroll view when finished editing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have created a Cocoa document based picture drawing application. I want that the
I have a simple document-based Cocoa app that acts as a viewer for .wav
Editing my nib for a document-based Cocoa application, I see that when I have
I have a Cocoa document-based app that (currently at least) functions as a basic
I have a document-based Cocoa application that has to start up a sub-process before
Assume I have a Cocoa-based Mac or iOS app. I'd like to run a
I am working on a Cocoa document based application. I have a menu item
I am trying to implement a delegate method for my Cocoa document-based application which
I have a document-based Cocoa app. During runtime, I load an additional nib from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.