This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This is a fix for some of the issues raised in #2414. One thing to note - there was some question as to whether win32yank works for everyone. I did find a possible workaround for that, if it's still an issue: ``` const textToPaste = clipboard.readText() const sanitizedTextLines = replaceAll(textToPaste, { "'": "''" }) await neovimInstance.command("let @+='" + sanitizedTextLines + "'") ``` I don't have a windows box to test this on, so perhaps we can add this code to `NeovimEditorCommands. pasteContents` later if needed.
- Loading branch information
Showing
4 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Test for pasting a large number of lines | ||
* | ||
* Regression test for #2414 | ||
*/ | ||
import * as assert from "assert" | ||
import * as Oni from "oni-api" | ||
|
||
import { createNewFile, getTemporaryFilePath, navigateToFile } from "./Common" | ||
|
||
export const test = async (oni: Oni.Plugin.Api) => { | ||
const filePath = createLargeTestFile() | ||
await oni.automation.waitForEditors() | ||
|
||
// open file with 2000 lines | ||
navigateToFile(filePath, oni) | ||
|
||
// select everything | ||
oni.automation.sendKeys("<s-v>") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "visual") | ||
oni.automation.sendKeys("G") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.activeBuffer.cursor.line === 1999) | ||
|
||
// copy and paste should result in 4000 lines | ||
await copy(oni) | ||
oni.automation.sendKeys("o") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "insert") | ||
await paste(oni, () => oni.editors.activeEditor.activeBuffer.lineCount === 4001) | ||
assert.strictEqual(oni.editors.activeEditor.activeBuffer.lineCount, 4001) | ||
|
||
// go to first line, and copy first word ('this') | ||
oni.automation.sendKeys("gg") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.activeBuffer.cursor.line === 0) | ||
oni.automation.sendKeys("v") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "visual") | ||
oni.automation.sendKeys("e") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.activeBuffer.cursor.column === 3) | ||
await copy(oni) | ||
|
||
// paste in the middle of the first word | ||
oni.automation.sendKeys("3l") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.activeBuffer.cursor.column === 3) | ||
oni.automation.sendKeys("i") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "insert") | ||
await paste(oni, () => oni.editors.activeEditor.activeBuffer.cursor.column === 7) | ||
|
||
const [firstLine] = await oni.editors.activeEditor.activeBuffer.getLines(0, 1) | ||
assert.strictEqual( | ||
firstLine, | ||
"thithiss is a line of 'text' that will be repeated a bunch of times to make for a large wall of 'text' to paste", | ||
) | ||
} | ||
|
||
import * as fs from "fs" | ||
import * as os from "os" | ||
|
||
const createLargeTestFile = (): string => { | ||
const filePath = getTemporaryFilePath("js") | ||
const line = | ||
"this is a line of 'text' that will be repeated a bunch of times to make for a large wall of 'text' to paste" | ||
|
||
const lines = [] | ||
for (let i = 0; i < 2000; i++) { | ||
lines.push(line) | ||
} | ||
|
||
fs.writeFileSync(filePath, lines.join(os.EOL)) | ||
return filePath | ||
} | ||
|
||
import { isMac } from "../../browser/src/Platform" | ||
|
||
const copy = async (oni: Oni.Plugin.Api) => { | ||
if (isMac()) { | ||
oni.automation.sendKeys("<m-c>") | ||
} else { | ||
oni.automation.sendKeys("<c-c>") | ||
} | ||
|
||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "normal") | ||
} | ||
|
||
const paste = async ( | ||
oni: Oni.Plugin.Api, | ||
waitConditionChecker: Oni.Automation.WaitConditionChecker, | ||
) => { | ||
if (isMac()) { | ||
oni.automation.sendKeys("<m-v>") | ||
} else { | ||
oni.automation.sendKeys("<c-v>") | ||
} | ||
|
||
await oni.automation.waitFor(waitConditionChecker) | ||
|
||
oni.automation.sendKeys("<esc>") | ||
await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "normal") | ||
} |