Skip to content
Snippets Groups Projects
Commit 3b560a46 authored by George Nachman's avatar George Nachman
Browse files

Fix a bug in how the selected text range was reported, noticed in issue 4482.

parent 0fc25a4b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2209,7 +2209,7 @@
A6099B0318D6B0FD00081FA9 /* iTermWarning.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = iTermWarning.h; sourceTree = "<group>"; tabWidth = 4; };
A6099B0418D6B0FD00081FA9 /* iTermWarning.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = iTermWarning.m; sourceTree = "<group>"; tabWidth = 4; };
A60BD9111B3913F6007D7F11 /* iTermTextViewAccessibilityHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTermTextViewAccessibilityHelper.h; sourceTree = "<group>"; };
A60BD9121B3913F6007D7F11 /* iTermTextViewAccessibilityHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermTextViewAccessibilityHelper.m; sourceTree = "<group>"; };
A60BD9121B3913F6007D7F11 /* iTermTextViewAccessibilityHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = iTermTextViewAccessibilityHelper.m; sourceTree = "<group>"; };
A60BD9181B3F5D76007D7F11 /* OpenDirectory.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenDirectory.framework; path = System/Library/Frameworks/OpenDirectory.framework; sourceTree = SDKROOT; };
A60D85A61A3A8105003AEE22 /* NSPasteboard+iTerm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSPasteboard+iTerm.h"; sourceTree = "<group>"; };
A60D85A71A3A8105003AEE22 /* NSPasteboard+iTerm.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSPasteboard+iTerm.m"; sourceTree = "<group>"; };
Loading
Loading
Loading
Loading
@@ -7054,6 +7054,25 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
[_selection endLiveSelection];
}
 
- (VT100GridCoordRange)accessibilityHelperSelectedRange {
iTermSubSelection *sub = _selection.allSubSelections.lastObject;
VT100GridCoordRange coordRange = sub.range.coordRange;
int minY = _dataSource.numberOfLines - _dataSource.height;
if (coordRange.start.y < minY) {
coordRange.start.y = 0;
coordRange.start.x = 0;
} else {
coordRange.start.y -= minY;
}
if (coordRange.end.y < minY) {
coordRange.end.y = 0;
coordRange.end.x = 0;
} else {
coordRange.end.y -= minY;
}
return coordRange;
}
- (NSString *)accessibilityHelperSelectedText {
return [self selectedTextAttributed:NO
cappedAtSize:0
Loading
Loading
Loading
Loading
@@ -36,8 +36,12 @@
// Select the range, which is in accessibility-space.
- (void)accessibilityHelperSetSelectedRange:(VT100GridCoordRange)range;
 
// Gets the selected range in accessibility-space.
- (VT100GridCoordRange)accessibilityHelperSelectedRange;
// Returns the contents of selected text in accessibility-space only.
- (NSString *)accessibilityHelperSelectedText;
@end
 
// This outsources accessibilty methods for PTYTextView. It's useful to keep
Loading
Loading
Loading
Loading
@@ -157,6 +157,16 @@
return coordRange;
}
 
- (NSRange)accessibilityRangeForCoordRange:(VT100GridCoordRange)coordRange {
NSUInteger location1 = [self rangeOfCharAtX:coordRange.start.x y:coordRange.start.y].location;
NSUInteger location2 = [self rangeOfCharAtX:coordRange.end.x y:coordRange.end.y].location;
NSUInteger start = MIN(location1, location2);
NSUInteger end = MAX(location1, location2);
return NSMakeRange(start, end - start);
}
- (NSNumber *)lineForIndex:(NSUInteger)theIndex {
return @([self lineNumberOfIndex:theIndex]);
}
Loading
Loading
@@ -299,20 +309,23 @@
}
 
- (NSValue *)selectedTextRange {
VT100GridCoord coord = [_delegate accessibilityHelperCursorCoord];
// quick fix for ZoomText for Mac - it does not query AXValue or other
// attributes that (re)generate _allText and especially lineBreak{Char,Index}Offsets_
// which are needed for rangeOfCharAtX:y:
[self allText];
NSRange range = [self rangeOfCharAtX:coord.x y:coord.y];
if (range.length > 0) {
range.length--;
VT100GridCoordRange coordRange = [_delegate accessibilityHelperSelectedRange];
NSRange range = [self accessibilityRangeForCoordRange:coordRange];
if (range.length == 0) {
range.location = NSNotFound;
}
return [NSValue valueWithRange:range];
}
 
- (NSArray *)selectedTextRanges {
return @[ [self accessibilityAttributeValue:NSAccessibilitySelectedTextRangeAttribute] ];
return @[ [self accessibilityAttributeValue:NSAccessibilitySelectedTextRangeAttribute handled:nil] ];
}
 
- (NSNumber *)insertionPointLineNumber {
Loading
Loading
@@ -397,7 +410,9 @@
 
- (id)accessibilityAttributeValue:(NSString *)attribute
handled:(BOOL *)handled {
*handled = YES;
if (handled) {
*handled = YES;
}
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
return [self role];
} else if ([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
Loading
Loading
@@ -423,7 +438,9 @@
} else if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) {
return [self visibleCharacterRange];
} else {
*handled = NO;
if (handled) {
*handled = NO;
}
return nil;
}
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment