I referred to SECoreTextView in a my compay project, Thanks for your SECoreTextView, that is pretty library for edit.
but the cursor position is incorrect when inserting a image or select a image from album in my project and RichTextEditor project, so i fixed the bug, but i failed to push source code.
NSUInteger index = currentCarePosition + 1;
if (index == NSNotFound || index >= self.text.length) {
index = self.text.length;
}
if (self.text.length == 0) {
index = 0;
}
Hi, Source contributors:
I referred to SECoreTextView in a my compay project, Thanks for your SECoreTextView, that is pretty library for edit. but the cursor position is incorrect when inserting a image or select a image from album in my project and RichTextEditor project, so i fixed the bug, but i failed to push source code.
The following is my code SECoreTextView.m:
(void)updateCaretPositionToNext:(NSInteger)currentCarePosition { if (!self.textLayout.textSelection) { self.textLayout.textSelection = [[SETextSelection alloc] init]; }
NSUInteger index = currentCarePosition + 1; if (index == NSNotFound || index >= self.text.length) { index = self.text.length; } if (self.text.length == 0) { index = 0; }
self.caretView.frame = [self caretRectForPosition:[SETextPosition positionWithIndex:index]];
[self.inputDelegate selectionWillChange:self];
self.textLayout.markedTextRange = NSMakeRange(NSNotFound, 0); self.textLayout.textSelection.selectedRange = NSMakeRange(index, 0); [self selectionChanged];
[self.inputDelegate selectionDidChange:self]; }
(void)insertObject:(id)object size:(CGSize)size; { NSInteger index = self.selectedRange.location; NSRange selectedNSRange = self.textLayout.textSelection.selectedRange; SETextRange markedTextRange = (SETextRange )self.markedTextRange; NSRange markedTextNSRange; if (markedTextRange) { markedTextNSRange = markedTextRange.range; } else { markedTextNSRange = NSMakeRange(NSNotFound, 0); }
SETextAttachment *attachment = nil; NSUInteger location = 0; if (markedTextRange && markedTextNSRange.location != NSNotFound) { location = markedTextNSRange.location; } else { location = selectedNSRange.location; }
NSString *replacementCharacter = OBJECT_REPLACEMENT_CHARACTER; attachment = [[SETextAttachment alloc] initWithObject:object size:size range:NSMakeRange(location, replacementCharacter.length)]; [self.attachments addObject:attachment];
[self insertText:replacementCharacter]; if (self.selectedRange.location != index + 1) { [self updateCaretPositionToNext:index]; } }
thanks. jeff