mirror of
https://github.com/MacDownApp/macdown.git
synced 2026-06-16 12:44:38 +00:00
Add link and image insertion shortcut
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user