Add link and image insertion shortcut

This commit is contained in:
Tzu-ping Chung
2014-06-16 16:20:30 +08:00
parent 62de1166a8
commit e2fe11351e
4 changed files with 39 additions and 2 deletions
+20
View File
@@ -492,6 +492,26 @@ static NSString * const kMPMathJaxCDN =
[self.editor toggleForMarkupPrefix:@"<!--" suffix:@"-->"];
}
- (IBAction)toggleLink:(id)sender
{
if ([self.editor toggleForMarkupPrefix:@"[" suffix:@"]()"])
{
NSRange selectedRange = self.editor.selectedRange;
NSUInteger location = selectedRange.location + selectedRange.length + 2;
self.editor.selectedRange = NSMakeRange(location, 0);
}
}
- (IBAction)toggleImage:(id)sender
{
if ([self.editor toggleForMarkupPrefix:@"![" suffix:@"]()"])
{
NSRange selectedRange = self.editor.selectedRange;
NSUInteger location = selectedRange.location + selectedRange.length + 2;
self.editor.selectedRange = NSMakeRange(location, 0);
}
}
- (IBAction)insertNewParagraph:(id)sender
{
NSRange range = self.editor.selectedRange;
@@ -25,7 +25,7 @@
strikethroughEnabled:(BOOL)isStrikethroughEnabled;
- (BOOL)deleteMatchingCharactersAround:(NSUInteger)location;
- (BOOL)unindentForSpacesBefore:(NSUInteger)location;
- (void)toggleForMarkupPrefix:(NSString *)prefix suffix:(NSString *)suffix;
- (BOOL)toggleForMarkupPrefix:(NSString *)prefix suffix:(NSString *)suffix;
- (BOOL)insertMappedContent;
- (BOOL)completeNextLine;
@@ -220,10 +220,11 @@ static const unichar kMPMarkupCharacters[] = {
return YES;
}
- (void)toggleForMarkupPrefix:(NSString *)prefix suffix:(NSString *)suffix
- (BOOL)toggleForMarkupPrefix:(NSString *)prefix suffix:(NSString *)suffix
{
NSRange range = self.selectedRange;
NSString *selection = [self.string substringWithRange:range];
BOOL isOn = NO;
// Selection is already marked-up. Clear markup and maintain selection.
NSUInteger poff = prefix.length;
@@ -234,6 +235,7 @@ static const unichar kMPMarkupCharacters[] = {
selection.length + poff + suffix.length);
[self insertText:selection replacementRange:sub];
range.location = sub.location;
isOn = NO;
}
// Selection is normal. Mark it up and maintain selection.
else
@@ -242,8 +244,10 @@ static const unichar kMPMarkupCharacters[] = {
prefix, selection, suffix];
[self insertText:text replacementRange:range];
range.location += poff;
isOn = YES;
}
self.selectedRange = range;
return isOn;
}
- (BOOL)insertMappedContent
@@ -417,6 +417,19 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="jLT-fP-2ps"/>
<menuItem title="Link" keyEquivalent="L" id="GIg-Wo-P8m">
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
<connections>
<action selector="toggleLink:" target="-1" id="Ebm-MA-ubE"/>
</connections>
</menuItem>
<menuItem title="Image" keyEquivalent="I" id="VkR-aw-5AU">
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
<connections>
<action selector="toggleImage:" target="-1" id="xuX-4U-p9x"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="E6f-72-5In"/>
<menuItem title="New Paragraph" id="zHE-JL-8eu">
<string key="keyEquivalent" base64-UTF8="YES">
DQ