jumbomoji searching works

This commit is contained in:
neon443 committed 2026-05-04 16:56:29 +01:00
1 parent 8be16d7c0e
commit 6a92586535
5 files changed
+179 -13

No files matched your search

+116 -13
View File
@@ -6,28 +6,131 @@
//
import Foundation
import CoreGraphics
struct JumboMoji {
struct JumboMoji: CustomStringConvertible, Hashable {
var baseName: String
var width: Int
var height: Int
var baseName: String
var type: JumboMoji.Style
var items: [String]
// init(baseName: String, items: [String]) {
// let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) }
//
//
// let coordinates = itemsBaseNameRemoved.map { $0.dropLast($0.split(separator: "-").last?.count ?? 0) }.split(separator: "-").map { Int(String($0)) }
// self.width = width
// self.height = height
// self.baseName = baseName
// self.type = type
// self.items = items
// }
var description: String {
self.baseName + " " + "\(width)x\(height)"
}
init(baseName: String, items: [String]) {
fatalError()
let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) }
var coordinates: [(Int, Int)] = []
for item in itemsBaseNameRemoved {
let split = item.dropLast(item.split(separator: "-").last?.count ?? 0)
print(split)
}
self.width = 0
self.height = 0
self.baseName = baseName
self.type = .grid
self.items = items
}
init?(components: [JumboMoji.Components]) {
guard components.allSatisfy({$0.baseName == components.first?.baseName}) else { return nil }
self.baseName = components.first!.baseName
let coords = components.map { CGPoint(x: $0.x, y: $0.y) }
guard let width = Int(coords.sorted { $0.x > $1.x }.first?.x.formatted() ?? "") else { return nil }
self.width = width
guard let height = Int(coords.sorted { $0.y > $1.y }.first?.y.formatted() ?? "") else { return nil }
self.height = height
self.type = .grid
self.items = components.map { "\($0.baseName)-\($0.coordinate)-\($0.id)-" }
}
enum Style {
case grid
case btn
}
static func from(names input: [String]) -> [JumboMoji] {
guard input.count > 0 else { return [] }
let input = input.sorted()
var jumboMojiComponents: [String: [JumboMoji.Components]] = [:]
for i in input.indices {
guard let currentComponents = splitIntoComponents(string: input[i]) else { continue }
if jumboMojiComponents.isEmpty || jumboMojiComponents[currentComponents.baseName] == nil {
jumboMojiComponents[currentComponents.baseName] = [currentComponents]
} else {
jumboMojiComponents[currentComponents.baseName]?.append(currentComponents)
}
}
print(jumboMojiComponents.mapValues({JumboMoji(components: $0)}).count)
var result: [JumboMoji] = []
for item in jumboMojiComponents {
if let jumbomoji = JumboMoji(components: item.value) {
result.append(jumbomoji)
}
}
return result
}
static func splitIntoComponents(string input: String) -> JumboMoji.Components? {
var string = input
var baseNameCount: Int = -1
for char in string {
if Int(String(char)) == nil {
baseNameCount += 1
} else { break }
}
guard baseNameCount > -1 && baseNameCount != input.count else { return nil }
let baseName = String(input.prefix(baseNameCount))
string = String(string.dropFirst(baseName.count+1))
guard input.dropFirst(baseNameCount).first == "-" else { return nil }
var coordCount = 1
var freeSkip = 1
for char in string {
if Int(String(char)) == nil {
guard freeSkip > 0 else { break }
freeSkip -= 1
continue
} else {
coordCount += 1
}
}
let coord = String(string.prefix(coordCount))
let coordSplit = coord.split(separator: "-").map { String($0) }
guard coord.contains("-") &&
Int(coordSplit.first ?? "x") != nil &&
Int(coordSplit.last ?? "x") != nil
else { return nil }
string = String(string.dropFirst(coordCount+1))
let id = string
return JumboMoji.Components(
baseName: baseName,
coordinate: coord,
id: id
)
}
struct Components {
var baseName: String
var coordinate: String
var x: Int {
let split = coordinate.split(separator: "-").first ?? "0"
return Int(split) ?? 0
}
var y: Int {
let split = coordinate.split(separator: "-").last ?? "0"
return Int(split) ?? 0
}
var id: String
}
}
@@ -0,0 +1,51 @@
//
// JumboMojiTestView.swift
// StickerSlack
//
// Created by neon443 on 04/05/2026.
//
import SwiftUI
struct JumboMojiTestView: View {
@State var hoarder: EmojiHoarder
@State var searchTerm: String = ""
@State var searchResult: [String] = []
var body: some View {
ScrollView {
TextField("search", text: $searchTerm)
.autocorrectionDisabled()
.onChange(of: searchTerm) { _ in
searchResult = hoarder.trie.search(for: searchTerm, previousQuery: nil, previousResult: nil)
}
ForEach(JumboMoji.from(names: searchResult), id: \.self) { jumboMoji in
VStack {
ForEach(0..<jumboMoji.height, id: \.self) { row in
ForEach(0..<jumboMoji.width, id: \.self) { col in
StickerPreview(sticker: hoarder.trie.dict[jumboMoji.items[row+col]] ?? .test)
}
}
// EmojiCollectionView(
// hoarder: hoarder,
// items: jumboMoji.items,
// pack: nil,
// width: CGFloat(jumboMoji.width),
// style: .jumboMoji
// )
Text(jumboMoji.description)
}
}
Divider()
// ForEach(searchResult, id: \.self) { item in
// Text(item)
// .border(JumboMoji.splitIntoComponents(string: item) == nil ? .clear : .red)
// .foregroundStyle(.gray)
// }
}
}
}
#Preview {
JumboMojiTestView(hoarder: EmojiHoarder())
}
+5
View File
@@ -112,6 +112,11 @@ struct SettingsView: View {
}
Section("Debug") {
NavigationLink {
JumboMojiTestView(hoarder: hoarder)
} label: {
Label("jumbomoji search", systemImage: "text.page.badge.magnifyingglass")
}
NavigationLink {
EmojiCollectionView(
hoarder: hoarder,
+1
View File
@@ -45,6 +45,7 @@ class Trie: ObservableObject {
}
func search(for query: String, previousQuery: String?, previousResult: Set<String>?) -> [String] {
guard !query.isEmpty else { return [] }
var result: Set<String> = wordlist
if let previousQuery,
let previousResult,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.