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

* add os detect util, use meta key on macos

* pr feedback
This commit is contained in:
Hamzah Mansour 2023-07-28 12:25:02 -07:00 committed by GitHub
parent 88f89cb953
commit 908b7c5bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View file

@ -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";
@ -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
@ -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);

View file

@ -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";
@ -16,6 +17,7 @@ export {
isBrowser,
isDark,
loadCss,
platform,
restoreScrollPosition,
saveScrollPosition,
setAuthCookie,

View file

@ -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;