Skip to content

Commit

Permalink
feat: add setting to enable chat selection! (can finally copy chat text)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Feb 19, 2024
1 parent 996d81b commit bc8409f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/optionsGuiScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ export const guiOptionsScheme: {
},
{
custom () {
return <>
<div></div>
<span style={{ fontSize: 9, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>Experimental</span>
<div></div>
</>
return <Category>Experimental</Category>
},
dayCycleAndLighting: {
text: 'Day Cycle',
Expand Down Expand Up @@ -139,6 +135,9 @@ export const guiOptionsScheme: {
unit: '',
delayApply: true,
},
custom () {
return <Category>Chat</Category>
},
chatWidth: {
max: 320,
unit: 'px',
Expand All @@ -151,6 +150,8 @@ export const guiOptionsScheme: {
},
chatOpacityOpened: {
},
chatSelect: {
},
}
],
controls: [
Expand Down Expand Up @@ -220,3 +221,9 @@ export const guiOptionsScheme: {
],
}
export type OptionsGroupType = 'main' | 'render' | 'interface' | 'controls' | 'sound' | 'advanced' | 'VR'

const Category = ({ children }) => <div style={{
fontSize: 9,
textAlign: 'center',
gridColumn: 'span 2'
}}>{children}</div>
1 change: 1 addition & 0 deletions src/optionsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultOptions = {
/** Actually might be useful */
showCursorBlockInSpectator: false,
renderEntities: true,
chatSelect: false,

// advanced bot options
autoRespawn: false,
Expand Down
7 changes: 5 additions & 2 deletions src/react/ChatContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Props = {
sendMessage?: (message: string) => boolean | void
fetchCompletionItems?: (triggerKind: 'implicit' | 'explicit', completeValue: string, fullValue: string, abortController?: AbortController) => Promise<string[] | void>
// width?: number
allowSelection?: boolean
}

export const chatInputValueGlobal = proxy({
Expand All @@ -53,7 +54,7 @@ export const fadeMessage = (message: Message, initialTimeout: boolean, requestUp
}, initialTimeout ? 5000 : 0)
}

export default ({ messages, opacity = 1, fetchCompletionItems, opened, sendMessage, onClose, usingTouch }: Props) => {
export default ({ messages, opacity = 1, fetchCompletionItems, opened, sendMessage, onClose, usingTouch, allowSelection }: Props) => {
const sendHistoryRef = useRef(JSON.parse(window.sessionStorage.chatHistory || '[]'))

const [completePadText, setCompletePadText] = useState('')
Expand Down Expand Up @@ -200,7 +201,9 @@ export default ({ messages, opacity = 1, fetchCompletionItems, opened, sendMessa

return (
<>
<div className={`chat-wrapper chat-messages-wrapper ${usingTouch ? 'display-mobile' : ''}`} hidden={isCypress()}>
<div className={`chat-wrapper chat-messages-wrapper ${usingTouch ? 'display-mobile' : ''}`} hidden={isCypress()} style={{
userSelect: opened && allowSelection ? 'text' : undefined,
}}>
{opacity && <div ref={chatMessages} className={`chat ${opened ? 'opened' : ''}`} id="chat-messages" style={{ opacity }}>
{messages.map((m) => (
<MessageLine key={m.id} message={m} />
Expand Down
2 changes: 2 additions & 0 deletions src/react/ChatProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default () => {
const { messagesLimit, chatOpacity, chatOpacityOpened } = options
const lastMessageId = useRef(0)
const usingTouch = useSnapshot(miscUiState).currentTouch
const { chatSelect } = useSnapshot(options)

useEffect(() => {
bot.addListener('message', (jsonMsg, position) => {
Expand All @@ -35,6 +36,7 @@ export default () => {
}, [])

return <ChatContainer
allowSelection={chatSelect}
usingTouch={!!usingTouch}
opacity={(isChatActive ? chatOpacityOpened : chatOpacity) / 100}
messages={messages}
Expand Down

0 comments on commit bc8409f

Please sign in to comment.