From 189298619b955aaf035b48106960d66e72a28ea1 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sat, 13 Dec 2014 15:10:29 +0800 Subject: [PATCH] Prevent cursor move on trailing newline insertion --- MacDown/Code/Document/MPDocument.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MacDown/Code/Document/MPDocument.m b/MacDown/Code/Document/MPDocument.m index 0bf25db..30bed6e 100644 --- a/MacDown/Code/Document/MPDocument.m +++ b/MacDown/Code/Document/MPDocument.m @@ -514,7 +514,11 @@ static void (^MPGetPreviewLoadingCompletionHandler(MPDocument *doc))() NSString *text = self.editor.string; NSUInteger end = text.length; if (end && ![newline characterIsMember:[text characterAtIndex:end - 1]]) + { + NSRange selection = self.editor.selectedRange; [self.editor insertText:@"\n" replacementRange:NSMakeRange(end, 0)]; + self.editor.selectedRange = selection; + } } return [super writeToURL:url ofType:typeName error:outError]; }