Skip to content

Commit ce1db9e

Browse files
committed
BugFix: Added Mac support for modifier keys
1 parent 8115a5d commit ce1db9e

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

main.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EditorView/Header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function headerExtension(plugin: CodeBlockCustomizerPlugin, settings: Cod
321321

322322
switch (modifierKey) {
323323
case ButtonModifierKeys.CTRL:
324-
return event.ctrlKey;
324+
return event.ctrlKey || event.metaKey;
325325
case ButtonModifierKeys.ALT:
326326
return event.altKey;
327327
case ButtonModifierKeys.SHIFT:

src/EditorView/InlineCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function inlineCodeExtension(plugin: CodeBlockCustomizerPlugin, settings:
111111
return;
112112

113113
const requiredKey = plugin.settings.pluginSettings.inlineCode.copyModifierKey;
114-
if ((requiredKey === InlineCodeModifierKeys.CTRL && !event.ctrlKey) || (requiredKey === InlineCodeModifierKeys.ALT && !event.altKey))
114+
if ((requiredKey === InlineCodeModifierKeys.CTRL && !event.ctrlKey && !event.metaKey) || (requiredKey === InlineCodeModifierKeys.ALT && !event.altKey))
115115
return;
116116

117117
const target = event.target as HTMLElement;

src/ReadingView/InlineCodeRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class InlineCodeRenderer extends MarkdownRenderChild {
9090
private createInlineCodeClickHandler(getTextToCopy: () => string): (event: MouseEvent) => void {
9191
return (event: MouseEvent) => {
9292
const requiredKey = this.plugin.settings.pluginSettings.inlineCode.copyModifierKey;
93-
if ((requiredKey === InlineCodeModifierKeys.CTRL && !event.ctrlKey) || (requiredKey === InlineCodeModifierKeys.ALT && !event.altKey)) {
93+
if ((requiredKey === InlineCodeModifierKeys.CTRL && !event.ctrlKey && !event.metaKey) || (requiredKey === InlineCodeModifierKeys.ALT && !event.altKey)) {
9494
return;
9595
}
9696

src/SettingsTab/Appearance.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Notice, Setting, TextComponent } from "obsidian";
1+
import { Notice, Platform, Setting, TextComponent } from "obsidian";
22

33
import { createDetailsGroup, SettingsPage, SettingsPageData, updateLanguageSpecificColorContainer } from "./Common";
44
import { getCurrentMode } from "src/Utils";
@@ -446,8 +446,8 @@ export class AppearanceSettings {
446446
.setName('Modifier key for copy')
447447
.setDesc('Select the key to hold while clicking to copy.')
448448
.addDropdown(dropdown => dropdown
449-
.addOption(InlineCodeModifierKeys.CTRL, 'Ctrl')
450-
.addOption(InlineCodeModifierKeys.ALT, 'Alt')
449+
.addOption(InlineCodeModifierKeys.CTRL, Platform.isMacOS ? 'Cmd' : 'Ctrl')
450+
.addOption(InlineCodeModifierKeys.ALT, Platform.isMacOS ? 'Option' : 'Alt')
451451
.setValue(this.plugin.settings.pluginSettings.inlineCode.copyModifierKey)
452452
.onChange(async (value: InlineCodeModifierKeys) => {
453453
this.plugin.settings.pluginSettings.inlineCode.copyModifierKey = value;

src/SettingsTab/Behavior.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DropdownComponent, Notice, Setting, TextComponent, ToggleComponent } from "obsidian";
1+
import { DropdownComponent, Notice, Platform, Setting, TextComponent, ToggleComponent } from "obsidian";
22

33
import CodeBlockCustomizerPlugin from "src/main";
44
import { createDetailsGroup, SettingsPage, SettingsPageData } from "./Common";
@@ -343,8 +343,8 @@ export class BehaviorSettings {
343343
.setDesc('Hold this key while clicking copy, select, or delete to include the fence lines in the action.')
344344
.addDropdown(dropdown => dropdown
345345
.addOption(ButtonModifierKeys.NONE, 'None')
346-
.addOption(ButtonModifierKeys.CTRL, 'Ctrl')
347-
.addOption(ButtonModifierKeys.ALT, 'Alt')
346+
.addOption(ButtonModifierKeys.CTRL, Platform.isMacOS ? 'Cmd' : 'Ctrl')
347+
.addOption(ButtonModifierKeys.ALT, Platform.isMacOS ? 'Option' : 'Alt')
348348
.addOption(ButtonModifierKeys.SHIFT, 'Shift')
349349
.setValue(this.plugin.settings.pluginSettings.codeblock.buttons.modifierKey)
350350
.onChange(async (value: ButtonModifierKeys) => {

0 commit comments

Comments
 (0)