Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions MarkEditMac/Sources/Main/AppWritingTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,42 @@ import MarkEditKit

@available(macOS 15.1, *)
enum AppWritingTools {
// Source/WebKit/Platform/spi/Cocoa/Modules/WritingTools_SPI/WritingToolsSPI.h
enum Tool: Int {
case panel = 0
case index = 0

case proofread = 1
case rewrite = 2
case makeFriendly = 11
case makeProfessional = 12
case makeConcise = 13
case summarize = 21
case createKeyPoints = 22
case makeList = 23
case makeTable = 24
case rewriteProofread = 3

case rewriteFriendly = 11
case rewriteProfessional = 12
case rewriteConcise = 13
case rewriteOpenEnded = 19

case transformSummarize = 21
case transformKeyPoints = 22
case transformList = 23
case transformTable = 24

case smartReply = 101

case compose = 201
}

static var requestedTool: Tool {
guard let controller = NSApp.windows
.compactMap(\.contentViewController)
.first(where: { $0.className == "WTWritingToolsViewController" }) else {
return .panel
return .index
}

// WTWritingToolsConfiguration
guard let target = invokeObject(controller, selector: "writingToolsConfiguration") else {
return .panel
return .index
}

return .init(rawValue: invokeInt(target, selector: "requestedTool")) ?? .panel
return .init(rawValue: invokeInt(target, selector: "requestedTool")) ?? .index
}

static var affordanceIcon: NSImage? {
Expand Down Expand Up @@ -70,12 +79,12 @@ enum AppWritingTools {
return false
}

return shouldReselect(with: .init(rawValue: menuItem.tag) ?? .panel)
return shouldReselect(with: .init(rawValue: menuItem.tag) ?? .index)
}

static func shouldReselect(with tool: Tool) -> Bool {
// Compose mode can start without text selections
tool != .compose
// These tools can start without text selections
tool != .smartReply && tool != .compose
}
}

Expand Down