mirror of
https://github.com/trudnai/Steve2.git
synced 2025-01-10 10:29:53 +00:00
- Speed up Paste
- CMD+A - Toolbar Copy+Paste buttons connected
This commit is contained in:
parent
5e7116aba0
commit
84e10b33d4
@ -1275,7 +1275,7 @@
|
||||
</buttonCell>
|
||||
</button>
|
||||
<connections>
|
||||
<action selector="Copy:" target="B8D-0N-5wS" id="Zqh-qn-MZ3"/>
|
||||
<action selector="SelectAll:" target="B8D-0N-5wS" id="OYm-4E-uTr"/>
|
||||
</connections>
|
||||
</toolbarItem>
|
||||
<toolbarItem implicitItemIdentifier="D00D9DE2-E274-4915-87A5-C94FEDDB6C22" label="Copy" paletteLabel="Copy" image="Copy" id="fQR-kz-ht6">
|
||||
|
@ -30,19 +30,26 @@ class ToolBarController: NSWindowController {
|
||||
ViewController.current?.Reset(sender)
|
||||
}
|
||||
|
||||
@IBAction func SelectAll(_ sender: Any) {
|
||||
// ViewController.current?.displayField.currentEditor()?.selectAll(nil)
|
||||
ViewController.current?.displayField.selectText(nil)
|
||||
}
|
||||
|
||||
@IBAction func Copy(_ sender: Any) {
|
||||
ViewController.current?.Copy()
|
||||
}
|
||||
|
||||
@IBAction func Paste(_ sender: Any) {
|
||||
ViewController.current?.Paste()
|
||||
}
|
||||
|
||||
@IBAction func Green(_ sender: Any) {
|
||||
// print("NSToolbarItem:", sender.tag)
|
||||
// print("NSToolbarItem:", sender.tag)
|
||||
ViewController.current?.MonoMonitorChange(color: "Green")
|
||||
}
|
||||
|
||||
@IBAction func Amber(_ sender: Any) {
|
||||
// print("NSToolbarItem:", sender.tag)
|
||||
// print("NSToolbarItem:", sender.tag)
|
||||
ViewController.current?.MonoMonitorChange(color: "Amber")
|
||||
}
|
||||
|
||||
|
@ -337,6 +337,42 @@ class ViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func SelectAll() {
|
||||
// displayField.currentEditor()?.selectAll(nil)
|
||||
displayField.selectText(nil)
|
||||
}
|
||||
|
||||
func Copy() {
|
||||
let pasteBoard = NSPasteboard.general
|
||||
pasteBoard.clearContents()
|
||||
// TODO: Find a better way to avoid index out of range error when the entire text area is selected
|
||||
let string = display.stringValue + " "
|
||||
if let selectedRange = displayField.currentEditor()?.selectedRange {
|
||||
let startIndex = string.index(string.startIndex, offsetBy: selectedRange.lowerBound)
|
||||
let endIndex = string.index(string.startIndex, offsetBy: selectedRange.upperBound)
|
||||
let selectedString = string[startIndex..<endIndex]
|
||||
pasteBoard.setString(String(selectedString), forType: .string)
|
||||
}
|
||||
}
|
||||
|
||||
func Paste() {
|
||||
let pasteBoard = NSPasteboard.general
|
||||
if let str = pasteBoard.string( forType: .string ) {
|
||||
print("PASTED:", str)
|
||||
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
for char in str.uppercased() {
|
||||
if let ascii = char.asciiValue {
|
||||
// TODO: Write separate Paste Accelerator
|
||||
disk_accelerator_speedup()
|
||||
kbdInput(ascii)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
||||
|
||||
if ( cpuMode == cpuMode_eco ) {
|
||||
@ -366,21 +402,18 @@ class ViewController: NSViewController {
|
||||
if event.modifierFlags.contains(.command) { // .shift, .option, .control ...
|
||||
if let chars = event.charactersIgnoringModifiers {
|
||||
switch chars {
|
||||
case "a":
|
||||
// print("CMD + A")
|
||||
SelectAll()
|
||||
return // to avoid deselect text
|
||||
|
||||
case "c":
|
||||
// print("CMD + C")
|
||||
Copy()
|
||||
|
||||
case "v":
|
||||
print("CMD + V")
|
||||
|
||||
let pasteBoard = NSPasteboard.general
|
||||
if let str = pasteBoard.string( forType: .string ) {
|
||||
print("PASTED:", str)
|
||||
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
for char in str.uppercased() {
|
||||
if let ascii = char.asciiValue {
|
||||
kbdInput(ascii)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// print("CMD + V")
|
||||
Paste()
|
||||
|
||||
default:
|
||||
super.keyDown(with: event)
|
||||
|
Loading…
x
Reference in New Issue
Block a user