Skip to content

Commit

Permalink
Add support for UserSpace.selectedText in input commands
Browse files Browse the repository at this point in the history
  • Loading branch information
zenangst committed Oct 11, 2023
1 parent 8ca0f69 commit c0bfaa0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion App/Sources/Core/Runners/CommandRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ final class CommandRunner: CommandRunning {
output = command.name
}
case .type(let typeCommand):
try await runners.type.run(typeCommand)
let input = snapshot.replaceSelectedText(typeCommand.input)
try await runners.type.run(input, mode: typeCommand.mode)
output = command.name
case .systemCommand(let systemCommand):
try await runners.system.run(systemCommand)
Expand Down
8 changes: 3 additions & 5 deletions App/Sources/Core/Runners/TypeCommandRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ final class TypeCommandRunner {
self.keyboardCommandRunner = keyboardCommandRunner
}

func run(_ command: TypeCommand) async throws {
let input = command.input

switch command.mode {
func run(_ input: String, mode: TypeCommand.Mode) async throws {
switch mode {
case .typing:
let newLines = CharacterSet.newlines
for character in input {
Expand All @@ -39,7 +37,7 @@ final class TypeCommandRunner {
case .instant:
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(command.input, forType: .string)
pasteboard.setString(input, forType: .string)

let keyCode = 9 // v
try keyboardCommandRunner.machPort?.post(keyCode, type: .keyDown, flags: .maskCommand)
Expand Down

0 comments on commit c0bfaa0

Please sign in to comment.