Add safety-space before pasting (#307)

* Add safety space when dropping in paths

* Add safety space when dropping in paths
This commit is contained in:
Armin Ronacher 2025-12-25 04:05:53 +01:00 committed by GitHub
parent fa716246ea
commit 65cbc22d7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -689,11 +689,21 @@ export class Editor implements Component {
const tabExpandedText = cleanText.replace(/\t/g, " ");
// Filter out non-printable characters except newlines
const filteredText = tabExpandedText
let filteredText = tabExpandedText
.split("")
.filter((char) => char === "\n" || char.charCodeAt(0) >= 32)
.join("");
// If pasting a file path (starts with /, ~, or .) and the character before
// the cursor is a word character, prepend a space for better readability
if (/^[/~.]/.test(filteredText)) {
const currentLine = this.state.lines[this.state.cursorLine] || "";
const charBeforeCursor = this.state.cursorCol > 0 ? currentLine[this.state.cursorCol - 1] : "";
if (charBeforeCursor && /\w/.test(charBeforeCursor)) {
filteredText = ` ${filteredText}`;
}
}
// Split into lines
const pastedLines = filteredText.split("\n");