Skip to content

Commit

Permalink
feat: hold shift to bypass file creation on long text paste
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Oct 8, 2024
1 parent 6ef2bd6 commit dcf9b3d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 29 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Consider giving a star ⭐ on [Github](https://github.com/pnd280/complexity).

💖 Support the development via [Ko-fi](https://ko-fi.com/pnd280) or [Paypal](https://paypal.me/pnd280).

## v0.0.3.11

_Release date: 8th Oct, 2024_

- **IMPROVE**: `Ctrl (Cmd) + Shift + V` to bypass file creation on long text paste. Normal paste will still create a file.

## v0.0.3.6

_Release date: 23rd Sep, 2024_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "complexity",
"displayName": "Complexity - Perplexity.ai supercharged",
"version": "0.0.3.10",
"version": "0.0.3.11",
"author": "pnd280",
"description": "⚡ Supercharge your Perplexity.ai",
"type": "module",
Expand Down
17 changes: 16 additions & 1 deletion src/content-script/hooks/useQueryBoxObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,25 @@ function interceptPasteEvent() {

$textarea.attr("data-paste-event-intercepted", "true");

$(document).off("keydown.interceptPasteEvent keyup.interceptPasteEvent");

let isShiftKeyPressed = false;

const handleKeyDown = (e: JQuery.TriggeredEvent) => {
if (e.key === "Shift") isShiftKeyPressed = true;
};

const handleKeyUp = (e: JQuery.TriggeredEvent) => {
if (e.key === "Shift") isShiftKeyPressed = false;
};

$(document).on("keydown.interceptPasteEvent", handleKeyDown);
$(document).on("keyup.interceptPasteEvent", handleKeyUp);

$textarea.on("paste", (e) => {
const clipboardEvent = e.originalEvent as ClipboardEvent;

if (clipboardEvent.clipboardData) {
if (clipboardEvent.clipboardData && isShiftKeyPressed) {
if (clipboardEvent.clipboardData.types.includes("text/plain")) {
e.stopImmediatePropagation();
}
Expand Down
1 change: 0 additions & 1 deletion src/content-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function initUiUxTweaks() {
UiTweaks.correctColorScheme();

UxTweaks.restoreLogoContextMenu();
UxTweaks.removeConflictedMobileOverlay();

const observe = (url: string) => {
const location = whereAmI(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ReactNode } from "react";

import { CplxUserSettings } from "@/cplx-user-settings/types/cplx-user-settings.types";
import KeyCombo from "@/shared/components/KeyCombo";

export type PopupSetting<T> = {
id: string;
label: string;
description?: string;
description?: ReactNode;
settingKey?: T;
versionRelease?: string;
experimental?: boolean;
Expand Down Expand Up @@ -63,7 +66,7 @@ export default class GeneralSettings {
id: "custom-markdown-block",
label: "Custom markdown block",
description:
"Precisely display the language of your code and enable syntax highlighting for natively unsupported languages. e.g. `gdscript`, `blade`, etc.",
"Precisely display the language of your code and enable syntax highlighting for natively unsupported languages. e.g. `vue`, `gdscript`, `blade`, etc.",
settingKey: "customMarkdownBlock",
},
{
Expand Down Expand Up @@ -93,7 +96,15 @@ export default class GeneralSettings {
id: "no-file-creation-on-paste",
label: "No file creation on long text paste",
settingKey: "noFileCreationOnPaste",
description: "Pasting long text no longer creates a file.",
description: (
<span>
<KeyCombo
className="tw-inline"
keys={["Control (⌘)", "Shift", "V"]}
/>{" "}
to paste long text without creating a file.
</span>
),
versionRelease: "0.0.1.0",
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/cplx-user-settings/components/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function SettingGroup<
key={id}
id={id}
className={cn({
"tw-items-start": !!description,
"tw-items-start": description != null,
})}
textLabel={
<div className="tw-flex tw-flex-col tw-gap-1">
Expand All @@ -194,7 +194,7 @@ function SettingGroup<
</span>
<span>{label}</span>
</div>
{description && (
{description != null && (
<div className="tw-ml-2 tw-text-xs tw-text-muted-foreground">
{description}
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/shared/components/KeyCombo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export default function KeyCombo({ keys }: { keys: string[] }) {
import { HTMLProps } from "react";

export default function KeyCombo({
keys,
...props
}: HTMLProps<HTMLSpanElement> & { keys: string[] }) {
return (
<span className="tw-flex tw-gap-1">
<span className={cn("tw-flex tw-gap-1")} {...props}>
{keys.map((key) => (
<span
key={key}
Expand Down
19 changes: 0 additions & 19 deletions src/utils/UxTweaks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { throttle } from "lodash-es";

import CplxUserSettings from "@/cplx-user-settings/CplxUserSettings";
import UiUtils from "@/utils/UiUtils";
import { whereAmI } from "@/utils/utils";
Expand Down Expand Up @@ -65,21 +63,4 @@ export default class UxTweaks {
e.stopPropagation();
});
}

static removeConflictedMobileOverlay() {
const handler = throttle(function () {
if (window.innerWidth < 768) {
const $navs = $(".h-mobileNavHeight");

if ($navs.length < 2) return;

$navs.first().remove();
}
}, 200);

requestIdleCallback(() => {
handler();
$(window).on("resize", handler);
});
}
}

0 comments on commit dcf9b3d

Please sign in to comment.