From 966328327e9f9454cd8a33b3f6af358191dfa40f Mon Sep 17 00:00:00 2001 From: Mute Date: Thu, 22 Aug 2024 18:13:04 +0000 Subject: [PATCH] stubs 107; history fixes --- mbchc.mjs | 31 ++++++++++--------------------- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/mbchc.mjs b/mbchc.mjs index 8e1ce65..b8febcf 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -204,7 +204,7 @@ const/**@type {Complete}*/C = { S_OPTS: {behavior: 'instant'}, const/**@type {InputHistory}*/H = { input: undefined, ids: undefined, bottom: undefined, // FIXME ids don't need to be a set, but I'm too tired right now enter: (ic, i, b, is) => yes(H.input = i, H.bottom = b, H.ids = is, ic.readOnly = true, val(ic.parentElement?.parentElement?.dataset, d => d['mbchcMode'] = 'h'), b && void W.ElementScrollToEnd('TextAreaChatLog')), - exit: (ic, r) => yes(ic.readOnly = false, val(ic.parentElement?.parentElement?.dataset, d => del(d, 'mbchcMode')), r && val(H.input, i => ic.value = i), val(H.bottom, b => b && void W.ElementScrollToEnd('TextAreaChatLog'))) + exit: (ic, r) => yes(ic.readOnly = false, val(ic.parentElement?.parentElement?.dataset, d => del(d, 'mbchcMode')), r && val(H.input, i => ic.value = i), val(H.bottom, b => b && void W.ElementScrollToEnd('TextAreaChatLog')), W.ChatRoomLastMessageIndex = W.ChatRoomLastMessage.length) } ass('MBCHC found, aborting loading', W.MBCHC === $) @@ -660,36 +660,25 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) //D.addEventListener('keydown', event => void this.focus_chat(event)) // Looks like the club got better at this mod.hookFunction('ChatRoomScrollHistory', 0, ([up]) => void val(U.ic, ic => { const input = ic.value, history = W.ChatRoomLastMessage - // FIXME later duplicates should override earlier ones // FIXME we'll make it better when the history is a proper ring buffer if (!ic.readOnly) { - const bottom = W.ElementIsScrolledToEnd('TextAreaChatLog') - if (m_t(input)) { - if (history.length < 2) return U.bell() - H.enter(ic, input, bottom, mut(new Set(history.keys()), s => s.delete(0))) // J'accuse! ChatRoomLastMessage is a total mess and a half. - } else { - const/**@type {Set}*/lines = new Set() // these only exist to filter duplicates - const/**@type {Set}*/ids = new Set() - history.forEach((l, i) => l !== input && l.startsWith(input) && cur(lines.size, s => lines.add(l) !== $ && s < lines.size && ids.add(i))) - if (m_t(ids)) return U.bell() - H.enter(ic, input, bottom, ids) - } + const/**@type {Map}*/map = new Map() + const/**@type {(l: string, i: number, I: string) => boolean}*/ cond = m_t(input) ? (_, i, __) => i > 0 : (l, _, i) => l !== i && l.startsWith(i) + if (m_t(history.reduce((ax, l, i) => cond(l, i, input) ? ax.set(l, i) : ax, map))) return U.bell() + H.enter(ic, input, W.ElementIsScrolledToEnd('TextAreaChatLog'), new Set(map.values())) } if (ic.readOnly) { // this can't be an else, because we mutate state above. To be honest, this will always be true, but I want to make sure. if (H.ids === $) return U.bell() // shouldn't happen? let found = -1 let first = -1 let last = -1 - for (const i of H.ids) { + for (const i of H.ids) { // these aren't necessarily in order if (up) { - if (i < W.ChatRoomLastMessageIndex) found = i - last = i + if (i < W.ChatRoomLastMessageIndex && i > found) found = i // the largest i that is less than index + if (i > last) last = i } else { - if (first < 0) first = i - if (i > W.ChatRoomLastMessageIndex) { - found = i - break - } + if (first < 0 || i < first) first = i + if (i > W.ChatRoomLastMessageIndex && (i < found || found < 0)) found = i // the smallest i that is greater than index } } if (found < 0) found = up ? last : first diff --git a/package-lock.json b/package-lock.json index 18f6753..0613efd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "107.13.0", "license": "SEE LICENSE IN LICENSE", "devDependencies": { - "bc-stubs": "^106.0.0", + "bc-stubs": "^107.0.0", "bondage-club-mod-sdk": "^1.2.0", "typescript": "^5.5.2", "xo": "^0.56.0" @@ -1074,9 +1074,9 @@ "dev": true }, "node_modules/bc-stubs": { - "version": "106.0.0", - "resolved": "https://registry.npmjs.org/bc-stubs/-/bc-stubs-106.0.0.tgz", - "integrity": "sha512-qUbBXFdTZNq+JUGJLpWCiqfMwSDu/i36fcoTtwfbHMV32lSkXsaLgqK7itOpDZIUTWcZhneN4DO2m6Jd7juk7w==", + "version": "107.0.0", + "resolved": "https://registry.npmjs.org/bc-stubs/-/bc-stubs-107.0.0.tgz", + "integrity": "sha512-PUEvMGe7dDm+lKy6YJIWv1xWCOBVt/WAn4xrG8mBUoGobZVBqOrg+x5lOV0HvG9fcBB8K5NEaXMciE5TOTWkBA==", "dev": true, "dependencies": { "socket.io-client": "4.6.1" diff --git a/package.json b/package.json index f0b593c..4504aea 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Mute", "type": "module", "devDependencies": { - "bc-stubs": "^106.0.0", + "bc-stubs": "^107.0.0", "bondage-club-mod-sdk": "^1.2.0", "typescript": "^5.5.2", "xo": "^0.56.0"