Skip to content

Commit

Permalink
Merge pull request #941 from Sequel-Ace/auto-pair-characters-font-939
Browse files Browse the repository at this point in the history
#fixed Auto pair characters changing font
  • Loading branch information
jamesstout committed Mar 5, 2021
2 parents e7b089b + 2c66e77 commit a792bd6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Source/Views/TextViews/SPTextView.m
Expand Up @@ -1111,9 +1111,23 @@ - (BOOL) wrapSelectionWithPrefix:(NSString *)prefix suffix:(NSString *)suffix

NSString *selString = [[self string] substringWithRange:currentRange];

NSMutableAttributedString *tmpStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@", prefix, selString, suffix]];

NSDictionary *fontAtt = [self.textStorage fontAttributesInRange:currentRange];

[tmpStr addAttribute:NSFontAttributeName
value:[fontAtt objectForKey:NSFontAttributeName]
range:NSMakeRange(0, tmpStr.length)];

// Register the wrap for undo
[self shouldChangeTextInRange:currentRange replacementString:[tmpStr string]];

// Replace the current selection with the selected string wrapped in prefix and suffix
[self.textStorage deleteCharactersInRange:currentRange];
[self.textStorage insertAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@", prefix, selString, suffix]] atIndex:currentRange.location];

// this insert changes the font to the global default, not the query editor font
// hence changing the font above.
[self.textStorage insertAttributedString:tmpStr atIndex:currentRange.location];

// Re-select original selection
NSRange innerSelectionRange = NSMakeRange(currentRange.location+1, [selString length]);
Expand All @@ -1123,6 +1137,8 @@ - (BOOL) wrapSelectionWithPrefix:(NSString *)prefix suffix:(NSString *)suffix
if([prefs boolForKey:SPCustomQueryAutoPairCharacters])
[[self textStorage] addAttribute:kAPlinked value:kAPval range:NSMakeRange(NSMaxRange(innerSelectionRange), 1)];

[self didChangeText];

return YES;
}

Expand Down

0 comments on commit a792bd6

Please sign in to comment.