# encoding: utf-8
# api: clicky
# type: init-gui
# version: 0.2
# title: Copy plain text
# description: override ⌨[Ctl-C] and [Ins] to copy just text/plain from color output
# category: ui
# state: stable
# hidden: 1
# nomenu: 1
#
# That's a workaround, which prevents copying RTF from RichTextBox/FlowDoc.
# Only extracts/converts from the current text selection.
#
# hook keyboard handler on FlowDocumentViewer/RichTextBox
$GUI.output.parent.Add_KeyUp({
Param($sender, $evt)
# Event object $evt contains .Key, and .KeyboardDevice.Modifiers
if (
($evt.Key -eq "Insert") -or
($evt.Key -eq "C") -and ($evt.KeyboardDevice.Modifiers -eq "Control")
) {
# get currently selected text(range)
if ($s = $GUI.Output.parent.Selection) {
$tr = New-Object System.Windows.Documents.TextRange -ArgumentList @($s.Start,$s.End)
if ($tr) {
Set-Clipboard ($tr.Text)
$evt.handled = $true
}
}
}
})