-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
298 additions
and
40 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
47 changes: 47 additions & 0 deletions
47
packages/text/src/TextField/service/TextFieldPasteService.test.ts
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,47 @@ | ||
import { execute } from "./TextFieldPasteService"; | ||
import { TextField } from "../../TextField"; | ||
import { describe, expect, it, beforeEach, afterAll } from "vitest"; | ||
|
||
describe("TextFieldPasteService.js test", () => | ||
{ | ||
beforeEach(() => { | ||
Object.assign(navigator, { | ||
"clipboard": { | ||
"text": "", | ||
readText () | ||
{ | ||
return Promise.resolve(this.text); | ||
}, | ||
writeText (data: string) | ||
{ | ||
this.text = data; | ||
return Promise.resolve(); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
Object.assign(navigator, { "clipboard": undefined }); | ||
}); | ||
|
||
it("execute test case1", async () => | ||
{ | ||
await navigator | ||
.clipboard | ||
.writeText("あいうえお\nかきくけこ\nさしすせそ"); | ||
|
||
|
||
|
||
const textField = new TextField(); | ||
textField.multiline = true; | ||
textField.focusIndex = 1; | ||
textField.selectIndex = 99; | ||
|
||
textField.text = "xyz"; | ||
expect(textField.text).toBe("xyz"); | ||
|
||
await execute(textField); | ||
expect(textField.text).toBe("あいうえお\nかきくけこ\nさしすせそ"); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/text/src/TextField/service/TextFieldPasteService.ts
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,20 @@ | ||
import type { TextField } from "../../TextField"; | ||
|
||
/** | ||
* @description コピーしたテキストをペーストします。 | ||
* Pastes the copied text. | ||
* | ||
* @param {TextField} text_field | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = async (text_field: TextField): Promise<void> => | ||
{ | ||
const text = await navigator.clipboard.readText(); | ||
if (text === "" || text_field.focusIndex === -1) { | ||
return ; | ||
} | ||
|
||
text_field.insertText(text); | ||
}; |
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
Oops, something went wrong.