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:
@@ -689,11 +689,21 @@ export class Editor implements Component {
|
|||||||
const tabExpandedText = cleanText.replace(/\t/g, " ");
|
const tabExpandedText = cleanText.replace(/\t/g, " ");
|
||||||
|
|
||||||
// Filter out non-printable characters except newlines
|
// Filter out non-printable characters except newlines
|
||||||
const filteredText = tabExpandedText
|
let filteredText = tabExpandedText
|
||||||
.split("")
|
.split("")
|
||||||
.filter((char) => char === "\n" || char.charCodeAt(0) >= 32)
|
.filter((char) => char === "\n" || char.charCodeAt(0) >= 32)
|
||||||
.join("");
|
.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
|
// Split into lines
|
||||||
const pastedLines = filteredText.split("\n");
|
const pastedLines = filteredText.split("\n");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user