aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/ScintillaView.mm
diff options
context:
space:
mode:
authornyamatongwe <nyamatongwe@gmail.com>2013-04-17 13:53:26 +1000
committernyamatongwe <nyamatongwe@gmail.com>2013-04-17 13:53:26 +1000
commit359a2e69d0ab976aa664a1658c07bda74a591da7 (patch)
treefa1137f56acd6352e268d329f23a05dc7c55fcb7 /cocoa/ScintillaView.mm
parentc597bc3b2ad86c3a6f2e0848a69df9d5060deb41 (diff)
downloadscintilla-mirror-359a2e69d0ab976aa664a1658c07bda74a591da7.tar.gz
Switch from implementing NSTextInput to its replacement NSTextInputClient
NSTextInput is slated for deprecation and NSTextInputClient allows the selection of accented characters through pressing and holding the base key.
Diffstat (limited to 'cocoa/ScintillaView.mm')
-rw-r--r--cocoa/ScintillaView.mm38
1 files changed, 31 insertions, 7 deletions
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
{