Re: Knowing how a Text Editing Session ended
Re: Knowing how a Text Editing Session ended
- Subject: Re: Knowing how a Text Editing Session ended
- From: Motti Shneor <email@hidden>
- Date: Tue, 27 Jul 2010 05:22:57 -0400
- Acceptlanguage: en-US
- Thread-topic: Knowing how a Text Editing Session ended
Thanks Keary,
In the mean time I already done lot's of Googling and dug into the docs, but what I found was quite discouraging.
First, the FieldEditor is a preconfigured instance of NSTextView attached to the window. There's only one field-editor serving all the NSTextField's of the window. I'm writing a plug-in, so both the window and other text fields are NOT MINE --- meaning, I don't want to alter the behavior of the "system" field editor. I'd rather install my delegate on it when creating my specific NSTextField, and revert the delegate when the user leaves the text field.
Next --- Overriding NSTextView's "insertTab" "insertBackTab" "cancelOperation" and the like won't work, because they aren't being called to start with, if a modifier key (option, command, ctrl) is pressed. I went into the docs and found the following frightening info:
Here's an excerpt from the Text Editing Programming Guide / About Key Bindings:
------------------------------------------------------------------------------------------------
The text input system uses a dictionary property list, called a key-bindings dictionary, to interpret keyboard events before passing them to the Input Method Kit framework for mapping to characters.
... processing a keyboard event ... an NSResponder subclass can choose to process certain keys and ignore others (for example, in a game) or to send the handleEvent: message to its input context.
The input context checks the event to see if it matches any of the keystrokes in the user’s key-bindings dictionary. A key-bindings dictionary maps a keystroke (including its modifier keys) to a method name. For example, the default key-bindings dictionary maps ^d (Control-D) to the method name deleteForward:.
If the keyboard event is in the dictionary, then the input context calls the text view’s doCommandBySelector: method with the selector associated with the dictionary entry.
If the input context cannot match the keyboard event to an entry in the key-bindings dictionary, it passes the event to the Input Method Kit for mapping to characters.
The standard key-bindings dictionary is in the file/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict.
You can override the standard dictionary entirely by providing a dictionary file at the path~/Library/KeyBindings/DefaultKeyBinding.dict.
However, defining custom key bindings dynamically (that is, while the application is running) is not supported.
------------------------------------------------------------------------------------------------
I examined this file, and indeed --- "insertTab" "insertBackTab" "insertNewLine" and the likes are there. Which means --- I can't introduce my "insertUpTab" at runtime!!!
Or, at the very least, I need to override a very basic keyboard event-handling method of the Field editor (keyDown) which I don't like to do.
Any observations?
I think I saw something about Forms (grouped text fields) that allow moving between fields using arrows (like in a spreadsheet) but I don't know how to set up a "Form" environment with no fields... or just one temporal text field...
Again, any hint will be appreciated.
On 22/07/2010, at 17:45, Keary Suska wrote:
> On Jul 22, 2010, at 2:47 AM, Motti Shneor wrote:
>
>> Thanks Mike --- Following your recommendation and the docs, I managed to extract the value of the @"NSTextMovement" key from the notification userInfo Dictionary, which contains just what I needed.
>>
>> However, I found that my problem is a bit deeper --- I want to finish the text editing session in 2 extra "nonstandard" ways (option-Tab, and option-shift-Tab) which in our specific context mean "Tab to the field below this field" and "Tab to the field above this field". the up and down equivalents to the Tab and BackTab.
>>
>> Unfortunately, the FieldEditor does not end the editing session in reacion to these key-presses, and inserts the characters into the text instead.
>>
>> My Question: How can I Persuade the FieldEditor to end an Editing Session when these specific key-combinations occur? Should I override something? Is there a specific Delegate for that?
>>
>> I thought that there should be something like:
>>
>> - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
>>
>> Where my delegate could decide if the current input (last key pressed) should cause the FieldEditor to resign editing on this field, or not.
>> But this delegate is only called when Tab, BackTab, Esc or Enter/Return are pressed ---- so I don't have the chance to decide.
>>
>> Any ideas?
>>
>> How can I configure the FieldEditor? Any sample code known to anyone?
>
> I would start with Googling around for modifying tab press behavior in an NSTextView, and/or how to override tab press behavior for an NSTextField. I believe Apple shows how to do the former in one of the standard docs. Somewhere you should find clues on how to capture arbitrary keystrokes, and then what to do with them. Also see all of the text system docs.
>
> HTH,
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
Motti Shneor
------------------------------------------
Senior Software Engineer
Waves Audio ltd.
Phone: +972-3-6084155
Mobile: +972-54-4470730
[mailto: email@hidden]
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden