1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-09-11 17:15:34 +03:00

Refactor slightly

This commit is contained in:
Tae Won Ha 2023-12-17 15:04:26 +01:00
parent 4c8ea2010d
commit 807ab05e9b
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -63,16 +63,6 @@ final class UGrid: CustomStringConvertible, Codable {
try container.encode(self.cells, forKey: .cells)
}
#if DEBUG
func dump() throws {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try encoder.encode(self)
try data.write(to: URL(fileURLWithPath: "/tmp/ugrid.dump.json"))
}
#endif
var description: String {
let result = "UGrid.flatCharIndex:\n" + self.cells.reduce("") { result, row in
result + "(\(row[0].flatCharIndex...row[self.size.width - 1].flatCharIndex)), "
@ -358,11 +348,8 @@ final class UGrid: CustomStringConvertible, Codable {
// marked text insert into cell directly
// marked text always following cursor position
func updateMark(
markedText: String,
selectedRange: NSRange
) {
assert(Thread.isMainThread, "should occur on main thread!")
func updateMark( markedText: String, selectedRange: NSRange ) {
assert(Thread.isMainThread)
var selectedRangeByCell = selectedRange
let markedTextArray: [String] = markedText.enumerated().reduce(into: []) { array, pair in
array.append(String(pair.element))
@ -404,5 +391,17 @@ final class UGrid: CustomStringConvertible, Codable {
private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.view)
}
extension UGrid {
func dump() throws {
#if DEBUG
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try encoder.encode(self)
try data.write(to: URL(fileURLWithPath: "/tmp/ugrid.dump.json"))
#endif
}
}
private let clearString = " "
private let wordSeparator = " "