From ce45f2e1141a177f18148b80ae1d1cadffb3e700 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Thu, 2 Jul 2015 06:03:05 +0200 Subject: [PATCH] move to end of line fix --- AppKit/CPTextView/CPTextView.j | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 0c6802a5e..887b9b7aa 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -1206,7 +1206,9 @@ var kDelegateRespondsTo_textShouldBeginEditing if (![self isSelectable]) return; - var fragment = [_layoutManager _firstLineFragmentForLineFromLocation:_selectionRange.location]; + var nglyphs = [_layoutManager numberOfCharacters], + loc = nglyphs == _selectionRange.location ? MAX(0, _selectionRange.location - 1) : _selectionRange.location; + fragment = [_layoutManager _firstLineFragmentForLineFromLocation:loc]; if (fragment) [self _establishSelection:CPMakeRange(fragment._range.location, 0) byExtending:flag]; @@ -1232,7 +1234,8 @@ var kDelegateRespondsTo_textShouldBeginEditing if (!fragment) return; - var loc = MAX(0, CPMaxRange(fragment._range) - 1); + var nglyphs = [_layoutManager numberOfCharacters], + loc = nglyphs == CPMaxRange(fragment._range) ? nglyphs : MAX(0, CPMaxRange(fragment._range) - 1); [self _establishSelection:CPMakeRange(loc, 0) byExtending:flag]; }