From c65704f3a87c14b9dbe16c976d7afcb0f175a63f Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 23 Dec 2012 01:55:28 +0000 Subject: - Correctly draw/update the selection highlight within the SPTextView used in the Custom Query Editor (among others) as the selection is changed with the mouse --- Source/SPTextView.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Source/SPTextView.m b/Source/SPTextView.m index dcb9dad7..5e324d28 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -3242,6 +3242,29 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS return YES; } +/** + * Selection range changes + * Listen to selection range change events and use changes of state between selection and no + * selection to redraw the hilight state + */ +- (NSRange)selectionRangeForProposedRange:(NSRange)proposedSelRange granularity:(NSSelectionGranularity)granularity +{ + NSUInteger currentSelectionLength = [self selectedRange].length; + + // If selection started/ended, redraw the background in the current query area + if ([self shouldHiliteQuery] && (currentSelectionLength && !proposedSelRange.length) || (!currentSelectionLength && proposedSelRange.length)) { + NSUInteger i = 0, rectCount = 0; + NSRect* rectsToUpdate = [[self layoutManager] rectArrayForCharacterRange:[self queryRange] + withinSelectedCharacterRange:[self queryRange] + inTextContainer:[self textContainer] + rectCount:&rectCount]; + for (i = 0; i < rectCount; i++) { + [self setNeedsDisplayInRect:rectsToUpdate[i]]; + } + } + + return [super selectionRangeForProposedRange:proposedSelRange granularity:granularity]; +} #pragma mark - #pragma mark delegates -- cgit v1.2.3