-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from NullVoxPopuli/byte-verses-character-index…
…-repro fix rust utf8 ranges vs js utf16 ranges
- Loading branch information
Showing
2 changed files
with
86 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Component from '@glimmer/component'; | ||
import { on } from '@ember/modifier'; | ||
|
||
import { getSnippetElement, toClipboard, withExtraStyles } from './copy-utils'; | ||
import Menu from './menu'; | ||
|
||
/** | ||
* This component is injected via the markdown rendering | ||
*/ | ||
export default class CopyMenu extends Component { | ||
copyAsText = (event: Event) => { | ||
let code = getSnippetElement(event); | ||
|
||
navigator.clipboard.writeText(code.innerText); | ||
}; | ||
|
||
copyAsImage = async (event: Event) => { | ||
let code = getSnippetElement(event); | ||
|
||
await withExtraStyles(code, () => toClipboard(code)); | ||
}; | ||
|
||
<template> | ||
<Menu data-test-copy-menu> | ||
<:trigger as |t|> | ||
<t.Default class="absolute top-3 right-4 z-10" data-test-copy-menu> | ||
📋 | ||
</t.Default> | ||
</:trigger> | ||
|
||
<:options as |Item|> | ||
<Item {{on "click" this.copyAsText}}> | ||
Copy as text | ||
</Item> | ||
<Item {{on "click" this.copyAsImage}}> | ||
Copy as image | ||
</Item> | ||
</:options> | ||
</Menu> | ||
</template> | ||
} |