-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Cursor position is incorrect with markup based editing #541
Comments
@Udayendu I cannot reproduce your error. |
@Udayendu Can you provide an example where the error can be reproduced? like this: https://codesandbox.io/embed/markdown-editor-for-react-izdd6?fontsize=14&hidenavigation=1&theme=dark |
@jaywcjlove Seems like its a white space issue: Take a look into the above image. The actual text is visible after selecting but the one we can see in the MarkDown editor is without white-space. That's why its not able to handle the cursor properly and positioned two spaces back. I tried editing the style property, but still no improvement:
Seems like the style properly have no impact in the MDEditor. |
I have the same problem. In this screenshot the cursor is actually at the end of the line, but clearly doesn't look that way: Tried upgrading to latest versions ( And here's how I'm using it (with Next 13.4.1): import '@uiw/react-markdown-preview/markdown.css'
import '@uiw/react-md-editor/markdown-editor.css'
export const DisplayRow = styled.div`
display: flex;
align-items: flex-start;
padding: ${({ theme }) => theme.spacing(2)} 0;
`
export const DisplayLabel = styled(EmphasisedLabel)`
color: ${({ theme }) => theme.colors.textEmphasis};
`
export const DisplayInputContainer = styled.div`
flex: 1;
`
const MDEditor = dynamic(() => import('@uiw/react-md-editor'), { ssr: false })
type MarkdownFieldProps = {
label: string
value: string | undefined
setValue: (val: string) => void
}
const MarkdownField = ({ label, value, setValue }: MarkdownFieldProps) => (
<DisplayRow>
<DisplayLabel>{label}:</DisplayLabel>
<DisplayInputContainer>
<MDEditor
aria-label={label}
value={value}
onChange={(val) => setValue(val || '')}
height={120}
data-color-mode="light"
className={label}
/>
</DisplayInputContainer>
</DisplayRow>
) Hope that's helpful. Great library though, appreciate the work that goes into it! |
Hmm so yeah I converted the above code to a Codesandbox and you're right @jaywcjlove that there's no issue 🤔 https://codesandbox.io/p/sandbox/exciting-pine-72x535
|
Ah so I think I see the issue. It appears it's because of this line:
i.e. the span has the font family that we use elsewhere in the app (in our case that's @Udayendu give that a try and let me know if it solves it for you too. @jaywcjlove is there a good reason that line needs to have the |
@matt2112 Avoid non-overlapping problems caused by font styles. |
@jaywcjlove Sorry unsure if that's a suggestion or an explanation. I mean why does the library override the application's global font family with the !important flag? Surely in most cases developers will want to use the same font as they have everywhere else no? But could well be something I'm missing. |
Yes, it will not easily cause style conflicts when users use it.
.w-md-editor-text-input,
.w-md-editor-text-pre > code,
.w-md-editor-text-pre
{
font-family: Arial,sans-serif !important;
} or .w-md-editor {
--md-editor-font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
} |
@matt2112 I tried applying this fix but for some reason its not able to resolve my issue. Are you able to fix your issue ? |
@jaywcjlove I tried to apply it using the CSS file and I can still see the issue. As you can see in the below image the font family is getting detected but its not applying the changes. I tried to check the outcome on multiple browser like firefox, chrome and edge. But still the behaviour is save. And even on both Ubuntu and MacOS too. Not sure why its not getting applied correctly. I create a test project and use the editor and its working there. But not in the main project. |
@Udayendu Is there a possibility that this font is not available locally? |
As mentioned earlier, I tried to reproduce it with some dummy code but its not reproducible.
I have "Helvetica, Arial" fonts available in the development server which is Ubuntu 22.04 LTS server vm installed with GUI. And on the client systems, all the 4 fonts are installed. |
@jaywcjlove btw FYI, this issue is happening when I am using any kind of markup parameters. For the normal texts, there is no issue atall. |
I just did some more testing and seems like apart from "Helvetica Neue" font, all other fonts have the issue and its not installed in the server thats hosting this application. You can see some dummy code https://codesandbox.io/s/white-dew-z786fl But usually these fonts required at the client side, is not it ? |
@Udayendu https://codesandbox.io/embed/serene-platform-j4ywzp?fontsize=14&hidenavigation=1&theme=dark - .w-md-editor-text-input {
+ .w-md-editor {
/* --md-editor-font-family: "Helvetica Neue", Helvetica, Arial, sans-serif !important; */
--md-editor-font-family: Arial;
} |
Thanks @jaywcjlove But when I am trying to make the title in any place of the page or insert the image, I can see this issue. Do you think something is trying to override some properly related to font ?? |
@Udayendu I can't help you if you give me an example where the error can be reproduced. |
@jaywcjlove Its difficult to reproduce out side of my project. The issue is that somewhere my code is causing a conflict with the required font for this editor. And may be thats causing the issue. Is there any way to override the default font and use only what we have specified for this editor. I know we have already tried with So I am really not sure how can I give you a reproducer. |
Closing this issue as I am unable to reproduce it outside of my project. |
When trying to write the page with markup, cursor position is not mapped correctly:
As you can see above, After a h4 type heading when I am trying to start writing the heading title, the cursor is still two positions back. But the actually it should look something like
#### |
. For normal text its not an issue but specially with heading type content, its causing the visualisation issue.how this can be fixed ?
The text was updated successfully, but these errors were encountered: