Skip to content

Commit ba45bab

Browse files
authored
feat: add troubleshooting section on copy-paste (#22)
* feat: add troubleshooting section on copy-paste * fix: suppress false positive error for missing ids * fix: rbrace not lbrace
1 parent c7cc6be commit ba45bab

File tree

10 files changed

+116
-15
lines changed

10 files changed

+116
-15
lines changed

src/docs/bindings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ menuOrder: 40
3535
- <Key>ctrl+a</Key>: Select all, move the cursor to the end of the query.
3636
- <Key>ctrl+x</Key>: Cut selected text.
3737
- <Key>ctrl+c</Key>: Copy selected text.
38-
- <Key>ctrl+v</Key>, <Key>ctrl+u</Key>: Paste selected text.
38+
- <Key>ctrl+v</Key>, <Key>ctrl+u</Key>, <Key>shift+insert</Key>, <Key>Right Click</Key>: Paste selected text.
3939
- <Key>ctrl+z</Key>: Undo.
4040
- <Key>ctrl+y</Key>: Redo.
4141
- <Key>ctrl+/</Key>, <Key>ctrl+\_</Key>: Toggle comments on selected line(s).

src/docs/troubleshooting.md

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,92 @@ menuOrder: 99
99
import Key from "$lib/components/key.svelte"
1010
</script>
1111

12+
Sorry to see you here. Terminals can be finicky. Please see below for solutions to common problems.
13+
14+
## Contents
15+
16+
1. [Key Bindings](#key-bindings)
17+
1. [Copy-Paste](#copying-and-pasting)
18+
1. [Colors](#colors)
19+
1. [Fonts](#fonts)
20+
1221
## Key Bindings
1322

14-
Harlequin can only react to key presses that are sent to it from the Terminal it is running in. Some common key presses, like <Key>ctrl+enter</Key>, aren't forwarded correctly by some terminals, or may be aliased to a different sort of event.
23+
Harlequin can only react to key presses that are sent to it from the Terminal it is running in. Some common key presses, like <Key>ctrl+enter</Key>, aren't forwarded correctly by some terminals, or may be aliased to a different key or even a different sort of event.
1524

1625
If you don't want to [upgrade your terminal](#terminal-recommendations), you can use the following aliases, which should be supported everywhere (if not, [open an issue](https://github.com/tconbeer/harlequin/issues)):
1726

1827
- Run query: use <Key>ctrl+j</Key>, not <Key>ctrl+enter</Key>.
19-
- Paste text: use <Key>ctrl+u</Key>, not <Key>ctrl+v</Key>.
2028
- Comment line: use <Key>ctrl+\_</Key> (underscore), not <Key>ctrl+/</Key>.
2129
- On a Mac: For all bindings, use <Key>^ Control</Key>, not <Key>⌘ Command</Key>.
2230

31+
[See here](#copying-and-pasting) for copy and paste.
32+
33+
Finally, Harlequin's footer, which lists some of the currently-active key bindings, is clickable. If a binding isn't working, you can click it in the footer to take the same action.
34+
35+
### Enabling Key Bindings in VS Code Terminal
36+
37+
VS Code intercepts a large number of key presses before they make it to the terminal, even when the terminal is focused. This includes <Key>ctrl+j</Key> (which hides or shows the VS Code terminal!). Fortunately, you can change this behavior in the VS Code settings. If you use a `settings.json` file, you can add this snippet:
38+
39+
```json
40+
&lbrace;
41+
"terminal.integrated.allowChords": false,
42+
"terminal.integrated.sendKeybindingsToShell": true,
43+
&rbrace;
44+
```
45+
46+
Otherwise, you can press <Key>F1</Key> to open the command palette, then type and select "Terminal: Configure Terminal Settings". Then make the following changes:
47+
48+
1. Uncheck the option "Terminal > Integrated: Allow Chords"
49+
2. Check the option "Terminal > Integrated: Send Keybindings to Shell" (you may have to scroll down nearly all the way).
50+
51+
## Copying and Pasting
52+
53+
<span class="text-purple italic font-bold">Note: Currently copying and pasting is only supported by the query editor, not the other widgets.</span>
54+
55+
Harlequin's query editor supports cut, copy, and paste. However, this is more complex than it seems. If these features are not working for you, there could be a number of root causes. This section walks through how copy-paste works in Harlequin, and offers some solutions for common problems.
56+
57+
### Internal Copy and Paste
58+
59+
Harlequin's query editor implements its own internal clipboard, so copying and pasting within the query editor should always work. To test the internal clipboard, select text in the query editor and press <Key>ctrl+c</Key> to copy it. Paste it with <Key>ctrl+u</Key> (`u`, not `v` for this step!). If that doesn't work, Harlequin isn't receiving those key presses from your terminal. Please [open an issue](https://github.com/tconbeer/harlequin/issues).
60+
61+
### Copying outside Harlequin, Pasting inside Harlequin
62+
63+
There are two mechanisms for Harlequin to receive clipboard data when you initiate a paste.
64+
65+
1. Harlequin receives a key press that it interprets as a paste command. This happens when you press <Key>ctrl+u</Key>, and depending on your terminal, may or may not happen when you press <Key>ctrl+v</Key>. When Harlequin interprets a key press as a paste command, it attempts to access the system clipboard and paste its contents. If it cannot access the system clipboard, Harlequin will paste the contents of its internal clipboard. To determine if Harlequin can access the system clipboard:
66+
67+
- Copy some text outside of Harlequin.
68+
- Focus on the Harlequin query editor, then press <Key>ctrl+u</Key> (`u`, not `v` for this step!).
69+
- If Harlequin does not paste anything, or if it pastes something different from what you just copied, Harlequin cannot access the system clipboard. You can work around this by pasting using your terminal's built-in paste functionality, or by fixing its access to the system clipboard (keep reading).
70+
71+
2. Harlequin receives a native `Paste` message from the terminal. To trigger a `Paste` message, you want to use the same keys that you would to paste into your shell. This might be <Key>ctrl+v</Key>, <Key>shift+insert</Key>, or a right click of your mouse. When Harlequin receives a `Paste` message, it will insert the contents of that message into the query editor. Since this doesn't rely on the clipboard, this should work on nearly any terminal, whether Harlequin and the terminal share a host or not. Many terminals allow you to configure the key or mouse bindings for `Paste`.
72+
73+
If Harlequin cannot access the system clipboard, there may be a couple of causes:
74+
75+
1. If Harlequin is installed on Linux, you may be missing a clipboard library. Try `sudo apt get xclip` or `sudo apt get xsel` to install a library that will allow Harlequin to access the system clipboard.
76+
2. Harlequin's host (the operating system where Harlequin is running) may have its clipboard disabled. This is common in GitHub Codespaces, CI runners, and other servers that don't typically support user input or a display. If you control the server, you can install or start an X Server (like X11) to enable the clipboard. As a workaround, try triggering a native `Paste` event in your terminal instead.
77+
3. If your terminal is attaching to a remote host to run Harlequin, e.g., via SSH, the terminal or SSH client may or may not support clipboard "redirection" (sharing the clipboard between the machines). In this case, Harlequin may be able to access its host's clipboard, but that clipboard won't be the same as the one you use for everything else. As a workaround, try triggering a native `Paste` event in your terminal instead (sadly this might also be disabled).
78+
79+
If all is lost, you can open a text file with Harlequin with <Key>ctrl+o</Key> or by clicking "Open Query" in the footer.
80+
81+
### Copying inside Harlequin, Pasting outside Harlequin
82+
83+
If you've made it this far, I'm so sorry. I hope you've learned something today.
84+
85+
The same dynamics from above apply, but we don't have the `Paste` event to move the data for us. The workarounds are:
86+
87+
1. You can try to use your terminal's native copy functionality. This is unlikely to do what you want, since it'll copy Harlequin's UI (borders, whitespace, etc), alongside your query. But if you want to try:
88+
89+
- In your terminal's settings, enable "Copy on Selection." You can test this in your shell -- if you select (highlight) text with your mouse, it should get copied to your clipboard.
90+
- In Harlequin, hold <Key>Shift</Key> while using your mouse to select the text you want to copy (on most terminals, this triggers selection when the terminal is in "app mode"). You'll know you're doing this right if the highlight color is different from what you normally see when highlighting text in Harlequin. Your selection should get copied to the clipboard (whitespace, `|`'s, and all).
91+
92+
2. You can save your query to a file and open it in another program. Press <Key>ctrl+s</Key> or click "Save Query" in the footer.
93+
2394
## Appearance
2495

2596
Harlequin should look great in your terminal. If it doesn't, it may be because we depend on your terminal and shell for rendering, and those may require some configuration on your machine.
2697

27-
<span id="colors"></span>
28-
2998
### Colors
3099

31100
Modern terminal emulators can display millions of colors, in a scheme called "truecolor." Older terminals could only display 256 colors, or even as few as 8.
@@ -59,14 +128,12 @@ To use a different font with Harlequin, download and install the font, and then
59128

60129
<span class="text-purple italic font-bold">Note for Mac Terminal.app Users:</span>
61130

62-
Only some fonts render right with the default Terminal app. [See here](https://textual.textualize.io/FAQ/#why-doesnt-textual-look-good-on-macos) for a workaround.
131+
Only some fonts render right with the default Terminal app. You may need to adjust your line spacing. [See here](https://textual.textualize.io/FAQ/#why-doesnt-textual-look-good-on-macos) for instructions.
63132

64133
<span class="text-purple italic font-bold">Note for WSL2 and Windows Terminal users:</span>
65134

66135
Windows Terminal runs in Windows and attaches your Linux shell over the WSL network. You need to install your font in **Windows** for this to work.
67136

68-
<span id="terminal-recommendations"></span>
69-
70137
## Terminal Recommendations
71138

72139
If you are using the default Mac Terminal or Windows Command Prompt, you may want to switch to a more modern terminal. The following terminals are free and come highly recommended:

src/lib/slugify.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function slugify(element: HTMLElement) {
2+
if (element === undefined) {
3+
return "";
4+
} else {
5+
return String(element.innerText)
6+
.toLowerCase()
7+
.replace(/[^a-z0-9 ]/g, "")
8+
.replace(/\s+/g, "-")
9+
.trim();
10+
}
11+
}

src/mdsvex/components/h2.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<h2 class="mt-8 font-accent text-2xl"><slot /></h2>
1+
<script lang="ts">
2+
import { slugify } from "$lib/slugify";
3+
let slotValue: HTMLElement;
4+
</script>
5+
6+
<h2 id={slugify(slotValue)} class="mt-8 font-accent text-2xl">
7+
<span bind:this={slotValue}><slot /></span>
8+
</h2>

src/mdsvex/components/h3.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<h3 class="mt-3 text-xl font-bold"><slot /></h3>
1+
<script lang="ts">
2+
import { slugify } from "$lib/slugify";
3+
let slotValue: HTMLElement;
4+
</script>
5+
6+
<h3 id={slugify(slotValue)} class="mt-3 text-xl font-bold">
7+
<span bind:this={slotValue}><slot /></span>
8+
</h3>

src/mdsvex/components/h4.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<h4 class="mb-2 text-lg font-bold italic"><slot /></h4>
1+
<script lang="ts">
2+
import { slugify } from "$lib/slugify";
3+
let slotValue: HTMLElement;
4+
</script>
5+
6+
<h4 id={slugify(slotValue)} class="mb-2 text-lg font-bold italic">
7+
<span bind:this={slotValue}><slot /></span>
8+
</h4>

src/mdsvex/components/pre.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<pre
2-
class="my-1 w-full overflow-x-auto rounded border border-purple bg-pink selection:bg-purple px-4 py-4 text-sm"><slot
2+
class="my-1 w-full overflow-x-auto rounded border border-purple bg-pink px-4 py-4 text-sm selection:bg-purple"><slot
33
/></pre>
44

55
<style>

src/mdsvex/docs.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<!-- pre component styles might get pruned, since the pre component is
1717
loaded manually in svelte.config.js. -->
18-
<span class="text-purple font-bold select-none"></span>
18+
<span class="select-none font-bold text-purple"></span>
1919
<div class="mb-8 overflow-x-auto">
2020
<slot />
2121
</div>

src/routes/tweets.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import nletcher from "$lib/assets/tweets/nletcher.jpg";
88
import willmcgugan from "$lib/assets/tweets/willmcgugan.jpg";
99
import _TylerHillery from "$lib/assets/tweets/_TylerHillery.jpg";
10-
1110
1211
const tweets: Tweet[] = [
1312
{
@@ -91,7 +90,7 @@
9190
body: `<p lang="en" dir="ltr">So much awesome! 😀💪 <a style="color: blue" href="https://t.co/D5eBrRGDK9">https://t.co/D5eBrRGDK9</a>`,
9291
created_at: "11:27 AM · Sep 20, 2023",
9392
src: "https://twitter.com/willmcgugan/status/1704547880202051694",
94-
}
93+
},
9594
];
9695
</script>
9796

svelte.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ const config = {
4242
"report-to": ["self"],
4343
},
4444
},
45+
prerender: {
46+
handleMissingId: "ignore",
47+
},
4548
},
4649
};
4750

0 commit comments

Comments
 (0)