mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 09:45:01 +00:00
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:
parent
88f89cb953
commit
908b7c5bb1
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
13
src/shared/utils/browser/platform.ts
Normal file
13
src/shared/utils/browser/platform.ts
Normal 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;
|
Loading…
Reference in a new issue