-
Notifications
You must be signed in to change notification settings - Fork 7
fix: AI Writing Studio unreadable text — blur occlusion, font mismatch, no scroll sync (#341) #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
930f801
fix(writer): unreadable AI Writing Studio text — blur occlusion, font…
qnbs 7a8c0b9
fix(writer): address PR #344 review findings — RTL fonts, custom font…
qnbs b6637f1
fix(ci): ignore the unfixable extract-zip OSV finding on this branch
qnbs f15820c
fix(tests): resolve CI typecheck failures from the review-fix batch
qnbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,45 @@ | ||
| import type React from 'react'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { Textarea } from './Textarea'; | ||
| import { forwardRef, useEffect, useState } from 'react'; | ||
| import { Textarea, type TextareaProps } from './Textarea'; | ||
|
|
||
| interface DebouncedTextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> { | ||
| interface DebouncedTextareaProps extends TextareaProps { | ||
| value: string; | ||
| onDebouncedChange: (value: string) => void; | ||
| debounceTimeout?: number; | ||
| } | ||
|
|
||
| export const DebouncedTextarea: React.FC<DebouncedTextareaProps> = ({ | ||
| value: propValue, | ||
| onDebouncedChange, | ||
| debounceTimeout = 750, | ||
| ...props | ||
| }) => { | ||
| const [internalValue, setInternalValue] = useState(propValue); | ||
| // QNBS-v3 (#344): forwards ref to the real textarea DOM node — a sibling DictationButton needs it to inject a dictated transcript, matching ManuscriptEditor's existing editorRef. | ||
| export const DebouncedTextarea = forwardRef<HTMLTextAreaElement, DebouncedTextareaProps>( | ||
| ({ value: propValue, onDebouncedChange, debounceTimeout = 750, ...props }, ref) => { | ||
| const [internalValue, setInternalValue] = useState(propValue); | ||
|
|
||
| // Sync with prop changes from external sources (e.g., undo/redo) | ||
| useEffect(() => { | ||
| setInternalValue(propValue); | ||
| }, [propValue]); | ||
| // Sync with prop changes from external sources (e.g., undo/redo) | ||
| useEffect(() => { | ||
| setInternalValue(propValue); | ||
| }, [propValue]); | ||
|
|
||
| // Debounce and notify parent of changes | ||
| useEffect(() => { | ||
| const handler = setTimeout(() => { | ||
| // If the user has typed something different from the last known prop value, | ||
| // notify the parent component. | ||
| if (propValue !== internalValue) { | ||
| onDebouncedChange(internalValue); | ||
| } | ||
| }, debounceTimeout); | ||
| // Debounce and notify parent of changes | ||
| useEffect(() => { | ||
| const handler = setTimeout(() => { | ||
| // If the user has typed something different from the last known prop value, | ||
| // notify the parent component. | ||
| if (propValue !== internalValue) { | ||
| onDebouncedChange(internalValue); | ||
| } | ||
| }, debounceTimeout); | ||
|
|
||
| // Cleanup: clear the timeout if the user types again. | ||
| return () => { | ||
| clearTimeout(handler); | ||
| }; | ||
| // This effect runs whenever the user's input changes. | ||
| }, [internalValue, onDebouncedChange, debounceTimeout, propValue]); | ||
| // Cleanup: clear the timeout if the user types again. | ||
| return () => { | ||
| clearTimeout(handler); | ||
| }; | ||
| // This effect runs whenever the user's input changes. | ||
| }, [internalValue, onDebouncedChange, debounceTimeout, propValue]); | ||
|
|
||
| const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
| setInternalValue(e.target.value); | ||
| }; | ||
| const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
| setInternalValue(e.target.value); | ||
| }; | ||
|
|
||
| return <Textarea {...props} value={internalValue} onChange={handleChange} />; | ||
| }; | ||
| return <Textarea ref={ref} {...props} value={internalValue} onChange={handleChange} />; | ||
| }, | ||
| ); | ||
| DebouncedTextarea.displayName = 'DebouncedTextarea'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import type { FC, RefObject } from 'react'; | ||
| import { useEffect } from 'react'; | ||
| import { useSpeechRecognition } from '../../hooks/useSpeechRecognition'; | ||
| import { useTranslation } from '../../hooks/useTranslation'; | ||
| import { Icon } from './Icon'; | ||
|
|
||
| interface DictationButtonProps { | ||
| targetRef: RefObject<HTMLTextAreaElement | null>; | ||
| } | ||
|
|
||
| // QNBS-v3 (#341/#344): extracted from Textarea.tsx's default-variant mic button so overlay consumers (ContextPanel, ManuscriptEditor) can render it as a sibling instead of losing dictation entirely. | ||
| export const DictationButton: FC<DictationButtonProps> = ({ targetRef }) => { | ||
| const { isListening, transcript, toggleListening, setTranscript } = useSpeechRecognition(); | ||
| const { t } = useTranslation(); | ||
|
|
||
| useEffect(() => { | ||
| if (transcript && targetRef.current) { | ||
| const input = targetRef.current; | ||
| const nativeInputValueSetter = Object.getOwnPropertyDescriptor( | ||
| window.HTMLTextAreaElement.prototype, | ||
| 'value', | ||
| )?.set; | ||
|
|
||
| if (nativeInputValueSetter) { | ||
| const currentValue = input.value; | ||
| const separator = currentValue.length > 0 && !currentValue.endsWith('\n') ? ' ' : ''; | ||
| const newValue = currentValue ? `${currentValue}${separator}${transcript}` : transcript; | ||
| nativeInputValueSetter.call(input, newValue); | ||
| const event = new Event('input', { bubbles: true }); | ||
| input.dispatchEvent(event); | ||
| } | ||
| setTranscript(''); | ||
| } | ||
| }, [transcript, setTranscript, targetRef]); | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={toggleListening} | ||
| className={`absolute right-3 bottom-3 p-2 rounded-full transition-all duration-sc-normal focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-[var(--sc-ring-focus)] z-20 ${ | ||
| isListening | ||
| ? 'text-[var(--sc-danger-fg)] bg-[var(--sc-danger-bg)] animate-pulse shadow-[0_0_0_4px_var(--sc-danger-fg)] scale-110' | ||
| : 'text-[var(--sc-text-muted)] bg-[var(--sc-surface-raised)]/80 hover:text-[var(--sc-text-primary)] hover:bg-[var(--glass-bg-hover)] shadow-sm border border-[var(--sc-border-subtle)]' | ||
| }`} | ||
| title={t('common.dictation.title')} | ||
| aria-label={isListening ? t('common.dictation.stop') : t('common.dictation.start')} | ||
| > | ||
| {isListening ? ( | ||
| <Icon name="microphone-solid" size="md" aria-hidden /> | ||
| ) : ( | ||
| <Icon name="microphone" size="md" aria-hidden /> | ||
| )} | ||
| </button> | ||
| ); | ||
| }; | ||
| DictationButton.displayName = 'DictationButton'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.