NSTextView - using up/down arrows moves paragraphs not lines - ios

I have an app that runs on iOS and uses UITextView to display rich text, and also runs on Mac and uses NSTextView to display rich text. These are separate apps, but with a lot of shared code. In both cases, the {NS,UI}Textview is programmatically created and placed on a canvas.
{NS,UI}TextView will wrap long lines of text as required. Long lines are called paragraphs and have NSParagraphStyles that can be applied across the whole paragraph (line spacing, head indent etc). Each paragraph is delineated by a "\n" character (or one of the Unicode equivalents). Paragraphs wrap across multiple lines, if required.
On iOS, when you have a long paragraph covering multiple lines... if you use the down/up arrow keys, the cursor moves up and down by lines (i.e. possibly within the same paragraph), which is as you expect.
On the Mac, with the same setup, the up/down arrow keys move the cursor up and down by paragraphs (i.e. multiple lines), which is very much not what you expect.
I have attached videos of the two cursor movements so you can see what happens.
I use the same code to create the {NS,UI}TextView, and I can't see why there is a difference.
Does anyone know what's going on here? I have not interfered with the arrow key handlers in any way (although I do implement textViewDidChangeSelection: in the delegate, and can confirm that the selection is changing per my comments above).
Any ideas would be most appreciated!
Thx.
iOS Cursor Down in a UITextView.
Mac Cursor Down in an NSTextView.

Found it! It was an errant calculation in the delegate function DoCommandBySelector.

Related

Split text if its content exceeds numbers line limit in Swift

Conditions:
UITextView that can contains X lines as maximum:disable scroll. (For example; max lines = 8)
A huge text content. (For example; 25 lines)
Language is English. (Word-wrap is compulsory)
How can I split text if its content exceeds numbers line limit?
I want to split text into array. Following the condition, the text should be split to 4 elements.
Update:
Actually what I want to achieve is like when I have a long text and I have the fix text container size (eg. UITextView) which cannot display all content, then there is a next button to reset container and display the left content. I thought that split string would help but it seems a wrong choice. I am trying what Matt's suggestion and hope the problem will be solved.
Your goal is not a good one. Instead of splitting the text into four arrays of text, it would be better to take advantage of Text Kit and let the layout manager split the text into four text containers (one NSLayoutManager, four NSTextContainers).
This could even be combined with your current use of a text view for display purposes: the four text containers could belong to four text views, and now you have four noneditable nonscrollable text views that automatically distribute the text between them, and you can just switch among those text views.
Here's an example with just two text views:
That's two UITextView objects governed by one NSLayoutManager, so that as the text becomes too long for the first text view it automatically flows into the second text view.
If you really wanted to, I suppose you could do what I just said and then use the layout manager to ask what it did, i.e. to read backwards from the line fragments to the glyphs to the character ranges and find out how it split the text into four text containers; but this seems silly when you consider that the problem is already solved before you even start to do that.

How do I set the style of the current paragraph in a UITextView?

I am writing an iPhone/iPad application that requires simple word processing capabilities. I'd like to give users the option to add styles to the current paragraph. For example:
Type several paragraphs into the UITextView
Put the cursor in the middle of the second paragraph
Press a button that says "center" or "ordered list" or something
The entire paragraph takes on that style
After reading through the documentation I can't figure out a way to do this without starting at the cursor, reading backwards to a line break, then reading forwards to the next line break, and recording that as the range. Then style the attributedText property. Is that the only way to do this?

Drag caret between text views

I am displaying a text document using many UITextViews, one for each paragraph*. When the user drags the caret around it obviously stops when he reaches the beginning or end of a paragraph. Is there any way of letting the user drag the caret between text views as if all the text was in one text view? In a way that is allowed in the App Store?
* There is a good reason for this, at least if my proof-of-concept actually succeeds in proving the concept.
This would be a pain in the ass to implement, but going off this answer as an indicator of cursor-on-text:
how to get selected text from uitextfield in iphone?
Check the position of the cursor, and if it matches the length of text in a textfield, start a gesture listener, and if it moves down and right, change the focus to the next textview. Keep your textviews in an array for easy accessing.

UITextVew tap in the middle of a word and place the cursor there

In the common behavior of UITextVew if the user taps in the middle of a word the cursor gets placed at the beginning of that word, or in other cases it selects the whole word.
I would like to entirely disable this and just let the user tap anywhere in the UITextVew and place the cursor just there.
Also I would appreciate to know if this is possible too for a UIWebView with contentEditable enabled.
Thanks in advance.
To get this behavior you have to build the text view yourself using core text. Or your only support iOS7. There you will have TextKit.

Is there a text editor with columns instead of scrolling?

Is there a text editor which offers horizontal, rather than vertical, scrolling (showing two pages side by side)?
I currently use TextMate, but would switch to any editor which offers this layout. I'm getting really bored of scrolling up and down, over and over.
I've attached a screenshot of MS Word, which has a side-by-side horizontal scroll view for documents longer than a page.
I want something like that, Any recommendations?
Emacs offers a follow-mode which you might find helpful ( see for instance here http://www.emacswiki.org/emacs/FollowMode).
A short description of how it is used and what it does:
You need to open a buffer in two windows and enter follow-mode using M-x follow-mode. This is actually a bit of a drawback, because you need to learn how to use emacs, if you don't know it already (imho learning how to use emacs is worth spending some time).
After entering follow-mode the second buffer will skip to the place where the first buffer ends, similar to the page-by-page view offered by Microsoft Word. Now if you move the cursor down one line at a time and you leave the first buffer window at the bottom, the cursor will appear at the top of the second. If you move further down and you are at the bottom of the second window, both buffers will scroll simultaneously, the same holds for page-wise scrolling using C-v and M-v.
If your monitor screen is wide enough, you can open a third window to further increase number of lines being displayed.
I have made a screenshot, which shows a text file opened in this mode: Screenshot auf Follow mode
Hmmm, it seems you are looking for layout features which you aren't likely to find in a text editor. Text editors are generally line based and don't understand the concept of pages. Text editors do things like code folding and allow lines to be wrapped or not. That is why text editors scroll in the vertical direction. These factors would affect pagination.
The concept of a page (and being able to lay them out side by side) doesn't really exist unless you are using a presentation manager such as a word processor or a desktop publishing package.
In vim: <Esc>:vsplit will open a second column for the file.
In all fairness, I should warn you that Vim has a steep learning curve, and will force you to wrap your head around new concepts like command mode / edit mode / visual mode. The results are definitely worth it, if you have the time to learn it.
I'm not sure if I know exactly what you want. Does Sublime Text 2's two-column layout with File > New View Into File do what you want?
A change on one side is reflected instantly in the other side, and you can scroll them independently. You can have up to four columns per window.
In LibreOffice Writer, go to View -> Zoom... and set Zoom factor to Fit width and height, and set View layout to Automatic. You can also set the number of columns manually, and if you choose two columns, you can use Book Mode.
With scroll-binding in vim, you can edit two files side by side: scroll-binding in Vim.
Show a text file with two columns in vim: http://vim.wikia.com/wiki/View_text_file_in_two_columns

Resources