diff options
Diffstat (limited to 'cocoa')
| -rw-r--r-- | cocoa/ScintillaView.h | 2 | ||||
| -rw-r--r-- | cocoa/ScintillaView.mm | 38 | 
2 files changed, 32 insertions, 8 deletions
| diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h index 87a443f73..996501788 100644 --- a/cocoa/ScintillaView.h +++ b/cocoa/ScintillaView.h @@ -48,7 +48,7 @@ extern NSString *SCIUpdateUINotification;   * InnerView is the Cocoa interface to the Scintilla backend. It handles text input and   * provides a canvas for painting the output.   */ -@interface InnerView : NSView <NSTextInput> +@interface InnerView : NSView <NSTextInputClient>  {  @private    ScintillaView* mOwner; diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index e01a2bf40..c39522009 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -292,9 +292,9 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)  //-------------------------------------------------------------------------------------------------- -// Adoption of NSTextInput protocol. +// Adoption of NSTextInputClient protocol. -- (NSAttributedString*) attributedSubstringFromRange: (NSRange) range +- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange  {    return nil;  } @@ -324,7 +324,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)  //-------------------------------------------------------------------------------------------------- -- (NSRect) firstRectForCharacterRange: (NSRange) aRange +- (NSRect) firstRectForCharacterRange: (NSRange) aRange actualRange: (NSRangePointer) actualRange  {    NSRect rect;    rect.origin.x = [ScintillaView directCall: mOwner @@ -366,11 +366,26 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)  /**   * General text input. Used to insert new text at the current input position, replacing the current   * selection if there is any. + * First removes the replacementRange.   */ -- (void) insertText: (id) aString +- (void) insertText: (id) aString replacementRange: (NSRange) replacementRange  {  	// Remove any previously marked text first.  	[self removeMarkedText]; + +	if (replacementRange.location == (NSNotFound-1)) +		// This occurs when the accent popup is visible and menu selected. +		// Its replacing a non-existant position so do nothing. +		return; + +	if (replacementRange.length > 0) +	{ +		[ScintillaView directCall: mOwner +				  message: SCI_DELETERANGE +				   wParam: replacementRange.location +				   lParam: replacementRange.length]; +	} +  	NSString* newText = @"";  	if ([aString isKindOfClass:[NSString class]])  		newText = (NSString*) aString; @@ -405,8 +420,9 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)   * @param aString The text to insert, either what has been marked already or what is selected already   *                or simply added at the current insertion point. Depending on what is available.   * @param range The range of the new text to select (given relative to the insertion point of the new text). + * @param replacementRange The range to remove before insertion.   */ -- (void) setMarkedText: (id) aString selectedRange: (NSRange) range +- (void) setMarkedText: (id) aString selectedRange: (NSRange)range replacementRange: (NSRange)replacementRange  {    NSString* newText = @"";    if ([aString isKindOfClass:[NSString class]]) @@ -438,6 +454,14 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)      mOwner.backend->SelectOnlyMainSelection();    } +  if (replacementRange.length > 0) +  { +    [ScintillaView directCall: mOwner +		      message: SCI_DELETERANGE +		       wParam: replacementRange.location +		       lParam: replacementRange.length]; +  } +    // Note: Scintilla internally works almost always with bytes instead chars, so we need to take    //       this into account when determining selection ranges and such.    std::string raw_text = [newText UTF8String]; @@ -523,14 +547,14 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)    return nil;  } -// End of the NSTextInput protocol adoption. +// End of the NSTextInputClient protocol adoption.  //--------------------------------------------------------------------------------------------------  /**   * Generic input method. It is used to pass on keyboard input to Scintilla. The control itself only   * handles shortcuts. The input is then forwarded to the Cocoa text input system, which in turn does - * its own input handling (character composition via NSTextInput protocol): + * its own input handling (character composition via NSTextInputClient protocol):   */  - (void) keyDown: (NSEvent *) theEvent  { | 
