Skip to content

Commit

Permalink
Set initial quote colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick committed Jul 30, 2023
1 parent e0cffd2 commit 13efe11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion web/pages/Chat/components/ChatPanes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ChatPanes: Component<{
const [editId, setEditId] = createSignal<string>()

onMount(() => {
if (isValid({ pane: ['character', 'preset', 'participants'] }, search)) {
if (isValid({ pane: ['character', 'preset', 'participants', 'ui', 'chat-settings'] }, search)) {
togglePane(search.pane)
}
})
Expand Down
25 changes: 12 additions & 13 deletions web/pages/Chat/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -591,41 +591,40 @@ function renderMessage(ctx: ContextState, text: string, isUser: boolean, adapter
// https://github.com/showdownjs/showdown/issues/669

const html = Purify.sanitize(
wrapQuotesInQTag(
wrapWithQuoteElement(
markdown.makeHtml(parseMessage(text, ctx, isUser, adapter)).replace(/&amp;nbsp;/g, '&nbsp;')
)
)

return html
}

function wrapQuotesInQTag(str: string) {
function wrapWithQuoteElement(str: string) {
return str.replace(
// we first match code blocks to ensure we do NOTHING to what's inside them
// then we match "regular quotes" and“'pretty quotes” as capture group
/```[\s\S]*?```|``[\s\S]*?``|`[\s\S]*?`|(\".+?\")|(\u201C.+?\u201D)/gm,
wrapMatchedQuoteInQTag
wrapCaptureGroups
)
}

/** For use as a String#replace(str, cb) callback */
function wrapMatchedQuoteInQTag(
function wrapCaptureGroups(
match: string,
textBetweenRegularQuotes?: string /** regex capture group 1 */,
textBetweenFancyQuotes?: string /** regex capture group 2 */
regularQuoted?: string /** regex capture group 1 */,
curlyQuoted?: string /** regex capture group 2 */
) {
if (textBetweenRegularQuotes) {
return '<q>"' + textBetweenRegularQuotes.replace(/\"/g, '') + '"</q>'
} else if (textBetweenFancyQuotes) {
return '<q>“' + textBetweenFancyQuotes.replace(/\u201C|\u201D/g, '') + '”</q>'
if (regularQuoted) {
return '<q>"' + regularQuoted.replace(/\"/g, '') + '"</q>'
} else if (curlyQuoted) {
return '<q>“' + curlyQuoted.replace(/\u201C|\u201D/g, '') + '”</q>'
} else {
return match
}
}

function sendAction(send: MessageProps['sendMessage'], { emote, action }: AppSchema.ChatAction) {
events.emit(EVENTS.setInputText, `*${emote}* ${action}`)
// send(`*${emote}* ${action}`, false)
function sendAction(_send: MessageProps['sendMessage'], { emote, action }: AppSchema.ChatAction) {
events.emit(EVENTS.setInputText, action)
}

function parseMessage(msg: string, ctx: ContextState, isUser: boolean, adapter?: string) {
Expand Down
4 changes: 2 additions & 2 deletions web/pages/Settings/UISettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const UISettings: Component = () => {
}
onInput={(color) => tryCustomUI({ chatQuoteColor: color })}
onChange={(color) => userStore.saveCustomUI({ chatQuoteColor: color })}
value={state.current.chatQuoteColor}
value={state.current.chatQuoteColor || '--text-800'}
/>

<Select
Expand Down Expand Up @@ -305,7 +305,7 @@ const UISettings: Component = () => {
editing={false}
msg={toUserMsg(
state.profile!,
'*I wave back* Hi {{char}}!\nFancy meeting you here!',
'*I wave back* Hi {{char}}!\nFancy meeting you here! I heard someone say "The weather is great today!"',
{ _id: '2' }
)}
onRemove={noop}
Expand Down
5 changes: 5 additions & 0 deletions web/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ function getUIsettings(guest = false) {

const ui = { ...UI.defaultUIsettings, ...settings }

if (!ui.dark.chatEmphasisColor) {
ui.dark.chatQuoteColor = UI.defaultUIsettings.dark.chatQuoteColor
ui.light.chatQuoteColor = UI.defaultUIsettings.light.chatQuoteColor
}

return ui
}

Expand Down

0 comments on commit 13efe11

Please sign in to comment.