diff options
| author | Tommaso Negri <me@tommasongr.com> | 2026-08-12 14:39:08 +0200 |
|---|---|---|
| committer | Tommaso Negri <me@tommasongr.com> | 2026-08-12 14:39:08 +0200 |
| commit | 7283e86d42d55d84fbeae02a98e9b252c83f6c56 (patch) | |
| tree | 93d2b895645c159a4929b245daa9c20ff307f437 | |
| parent | f16c284b969ef0728fdbffef94f4fd5d02e44c3e (diff) | |
| download | bar-7283e86d42d55d84fbeae02a98e9b252c83f6c56.tar.gz bar-7283e86d42d55d84fbeae02a98e9b252c83f6c56.zip | |
make cell more efficient by diffing them by rawValue + highlight
| -rw-r--r-- | Sources/bar/Models/Cell.swift | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Sources/bar/Models/Cell.swift b/Sources/bar/Models/Cell.swift index 9e0d46f..48798ba 100644 --- a/Sources/bar/Models/Cell.swift +++ b/Sources/bar/Models/Cell.swift @@ -1,4 +1,3 @@ -import Foundation import RegexBuilder import SwiftUI @@ -30,7 +29,11 @@ import SwiftUI /// window manager workspaces and which one is active. struct Cell: RawRepresentable, Identifiable { /// Stable identity for SwiftUI diffing. - let id = UUID() + /// + /// The id is constructed by the rawValue + highlight + /// so that SwiftUI redraws the cell only on content + /// change and not every time the cell is computed. + let id: String /// The represented text content. let rawValue: String @@ -61,6 +64,7 @@ struct Cell: RawRepresentable, Identifiable { guard let match = rawValue.firstMatch(of: pattern) else { self.rawValue = rawValue self.highlight = 0 + self.id = "\(rawValue):0" return } @@ -71,5 +75,6 @@ struct Cell: RawRepresentable, Identifiable { } self.rawValue = String(match.output.2) + self.id = "\(self.rawValue):\(self.highlight)" } } |
