aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2016-11-11 13:03:51 +1100
committerNeil <nyamatongwe@gmail.com>2016-11-11 13:03:51 +1100
commitbd6b3866b43b54f2fdb58ea5435b04f75c0d2159 (patch)
tree569e85185b0608dd37bb5d60ef7c3b141ab0fd84
parent76f0b9d9651c348fb8bc0c3280616ec63ba58808 (diff)
downloadscintilla-mirror-bd6b3866b43b54f2fdb58ea5435b04f75c0d2159.tar.gz
Bug [#1881]. Fix IME bug where selectedRange wasn't implementing correctly.
Also return nil from attributedSubstringForProposedRange for ranges outside document as this is specified behaviour.
-rw-r--r--cocoa/ScintillaView.h1
-rw-r--r--cocoa/ScintillaView.mm30
2 files changed, 27 insertions, 4 deletions
diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h
index 079e42116..c397cad8d 100644
--- a/cocoa/ScintillaView.h
+++ b/cocoa/ScintillaView.h
@@ -142,6 +142,7 @@ extern NSString *const SCIUpdateUINotification;
- (void) setEditable: (BOOL) editable;
- (BOOL) isEditable;
- (NSRange) selectedRange;
+- (NSRange) selectedRangePositions;
- (NSString*) selectedString;
diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm
index 491aba572..83e8f5398 100644
--- a/cocoa/ScintillaView.mm
+++ b/cocoa/ScintillaView.mm
@@ -365,6 +365,10 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
+ const NSInteger lengthCharacters = self.accessibilityNumberOfCharacters;
+ if (aRange.location > lengthCharacters) {
+ return nil;
+ }
const NSRange posRange = mOwner.backend->PositionsFromCharacters(aRange);
// The backend validated aRange and may have removed characters beyond the end of the document.
const NSRange charRange = mOwner.backend->CharactersFromPositions(posRange);
@@ -505,9 +509,11 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)
- (NSRange) selectedRange
{
- const long positionBegin = [mOwner message: SCI_GETSELECTIONSTART];
- const long positionEnd = [mOwner message: SCI_GETSELECTIONEND];
- NSRange posRangeSel = NSMakeRange(positionBegin, positionEnd-positionBegin);
+ const NSRange posRangeSel = [mOwner selectedRangePositions];
+ if (posRangeSel.length == 0)
+ {
+ return NSMakeRange(NSNotFound, 0);
+ }
return mOwner.backend->CharactersFromPositions(posRangeSel);
}
@@ -571,7 +577,8 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)
}
// Ensure only a single selection.
mOwner.backend->SelectOnlyMainSelection();
- replacementRange = [self selectedRange];
+ const NSRange posRangeSel = [mOwner selectedRangePositions];
+ replacementRange = mOwner.backend->CharactersFromPositions(posRangeSel);
}
}
@@ -1993,6 +2000,21 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context
//--------------------------------------------------------------------------------------------------
+/**
+ * Return the main selection as an NSRange of positions (not characters).
+ * Unlike selectedRange, this can return empty ranges inside the document.
+ */
+
+- (NSRange) selectedRangePositions
+{
+ const sptr_t positionBegin = [self message: SCI_GETSELECTIONSTART];
+ const sptr_t positionEnd = [self message: SCI_GETSELECTIONEND];
+ return NSMakeRange(positionBegin, positionEnd-positionBegin);
+}
+
+
+//--------------------------------------------------------------------------------------------------
+
- (void)insertText: (id) aString
{
if ([aString isKindOfClass:[NSString class]])