Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper modifier key in markdown text input on macOS #1995

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/shared/components/common/markdown-textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBrowser } from "@utils/browser";
import { isBrowser, platform } from "@utils/browser";
import { numToSI, randomStr } from "@utils/helpers";
import autosize from "autosize";
import classNames from "classnames";
Expand All @@ -21,7 +21,6 @@ import { EmojiPicker } from "./emoji-picker";
import { Icon, Spinner } from "./icon";
import { LanguageSelect } from "./language-select";
import ProgressBar from "./progress-bar";

interface MarkdownTextAreaProps {
/**
* Initial content inside the textarea
Expand Down Expand Up @@ -477,7 +476,7 @@ export class MarkdownTextArea extends Component<
// Keybind handler
// Keybinds inspired by github comment area
handleKeyBinds(i: MarkdownTextArea, event: KeyboardEvent) {
if (event.ctrlKey || event.metaKey) {
if (platform.isMac() ? event.metaKey : event.ctrlKey) {
switch (event.key) {
case "k": {
i.handleInsertLink(i, event);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/utils/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dataBsTheme from "./data-bs-theme";
import isBrowser from "./is-browser";
import isDark from "./is-dark";
import loadCss from "./load-css";
import platform from "./platform";
import restoreScrollPosition from "./restore-scroll-position";
import saveScrollPosition from "./save-scroll-position";
import setAuthCookie from "./set-auth-cookie";
Expand All @@ -16,6 +17,7 @@ export {
isBrowser,
isDark,
loadCss,
platform,
restoreScrollPosition,
saveScrollPosition,
setAuthCookie,
Expand Down
13 changes: 13 additions & 0 deletions src/shared/utils/browser/platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { isBrowser } from "@utils/browser";

const platformString = () =>
navigator.platform?.match(/mac|win|linux/i)?.[0].toLowerCase();
const getPlatformPredicate = (platform: string) => () =>
isBrowser() && platformString() === platform;
const isWin = getPlatformPredicate("win");
const isMac = getPlatformPredicate("mac");
const isLinux = getPlatformPredicate("linux");

const platform = { isWin, isMac, isLinux };

export default platform;