react-codemirror icon indicating copy to clipboard operation
react-codemirror copied to clipboard

Controlling the autocompletion tooltip position

Open mgoldenbe opened this issue 2 years ago • 10 comments

The tooltip appears very far to the right from the current position of the cursor:

image

The surrounding element does not have any transformations. I would like to have the tooltip appear immediately to the right and below the cursor. Since it looks like the left attribute is computed dynamically, here is what I am trying to affect it:

.cm-tooltip-autocomplete.cm-tooltip.cm-tooltip-below {
    transform: translateX(-12em);
}

I tried using px and rem, but cannot figure out the right formula.

So, how can I achieve that the autocompletion tooltip should appear immediately to the right and below the cursor?

mgoldenbe avatar Jun 14 '23 20:06 mgoldenbe

image

@mgoldenbe I did not reproduce your error.

jaywcjlove avatar Jun 15 '23 10:06 jaywcjlove

https://codemirror.net/examples/tooltip/

You can customize your own Tooltips.

jaywcjlove avatar Jun 15 '23 10:06 jaywcjlove

I had this in my SCSS:

.learning-content {
    container: learning-content / inline-size;
    position: relative;
    display: inline-block;
    width: 100%;
    height: inherit;
}

This class was used by a non-immediate parent of the editor. There was no @container query that used it, but somehow the container property resulted in bad tooltip position...

mgoldenbe avatar Jun 15 '23 19:06 mgoldenbe

@mgoldenbe Please provide a reproducible example, thanks.

jaywcjlove avatar Jun 16 '23 00:06 jaywcjlove

@mgoldenbe You are using position: absolute; which confuses me. resulting in incorrectly calculated positions.

jaywcjlove avatar Jun 16 '23 09:06 jaywcjlove

@jaywcjlove What's confusing you about it? Are you saying this is normal behavior to be expected? Also, without the container property it works just fine even with the absolute positioning...

mgoldenbe avatar Jun 17 '23 18:06 mgoldenbe

image

The way you use position confuses me.

@mgoldenbe In short your styles affect the codemirror editor, so you need to make changes.

jaywcjlove avatar Jun 18 '23 00:06 jaywcjlove

What's wrong about the right property you deleted? If you make assumptions about CSS, you should state them explicitly in the documentation. Otherwise, your library must work correctly with any valid CSS.

mgoldenbe avatar Jun 18 '23 06:06 mgoldenbe

Facing the same issue with autocomplete when component is nested inside something with @container... Just wanted to share a workaround that worked in my case: disable autocomplete from the basicSetup options, and enable using the codemirror extension

import { autocompletion } from "@codemirror/autocomplete";

<ReactCodeMirror 
  ...
  basicSetup={{
    ...
    autocomplete: false
  }}
  extensions={[..., autocompletion()]}
/> 

EDIT: this ends up not working... so nevermind!

ryandvmartin avatar Dec 04 '23 18:12 ryandvmartin