-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #22808 from jczekalski/migrate-copy-selection-helper
Migrate CopySelectionHelper.js from class component to hook
- Loading branch information
Showing
3 changed files
with
37 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import {useEffect} from 'react'; | ||
import ExpensiMark from 'expensify-common/lib/ExpensiMark'; | ||
import CONST from '../CONST'; | ||
import KeyboardShortcut from '../libs/KeyboardShortcut'; | ||
import Clipboard from '../libs/Clipboard'; | ||
import SelectionScraper from '../libs/SelectionScraper'; | ||
|
||
function copySelectionToClipboard() { | ||
const selection = SelectionScraper.getCurrentSelection(); | ||
if (!selection) { | ||
return; | ||
} | ||
const parser = new ExpensiMark(); | ||
if (!Clipboard.canSetHtml()) { | ||
Clipboard.setString(parser.htmlToMarkdown(selection)); | ||
return; | ||
} | ||
Clipboard.setHtml(selection, parser.htmlToText(selection)); | ||
} | ||
|
||
export default function useCopySelectionHelper() { | ||
useEffect(() => { | ||
const copyShortcutConfig = CONST.KEYBOARD_SHORTCUTS.COPY; | ||
const unsubscribeCopyShortcut = KeyboardShortcut.subscribe( | ||
copyShortcutConfig.shortcutKey, | ||
copySelectionToClipboard, | ||
copyShortcutConfig.descriptionKey, | ||
copyShortcutConfig.modifiers, | ||
false, | ||
); | ||
|
||
return unsubscribeCopyShortcut; | ||
}, []); | ||
} |
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