Hello,
I have implemented the functionality of a tooltip box when hovering functions in code editor v6, using Angular.
The code editor changes color whenever the navigation mode goes from dark to light and vice-versa. However, the tooltip box it’s always the same color. Is there a way of styling this tooltip box’s background and text color?
This is my code (I’ve omitted some parts to simplify it):
// THEMES
import {oneDark} from "@codemirror/theme-one-dark";
import {basicLight} from "cm6-theme-basic-light";
/* Other essential imports ... */
initCodeMirror() {
const theme = this.getTheme() === 'dark' ? oneDark : basicLight;
let editorTheme = new Compartment();
const wordHover = hoverTooltip((view, pos, side) => {
let {from, to, text} = view.state.doc.lineAt(pos)
let start = pos, end = pos
while (start > from && /\w/.test(text[start - from - 1])) start--
while (end < to && /\w/.test(text[end - from])) end++
if (start == pos && side < 0 || end == pos && side > 0)
return null
let word = text.slice(start - from, end - from);
if (this.isInFunctions(word)){
let text = "tooltip info text"
return {
pos: start,
end,
above: false,
create(view) {
let dom = document.createElement("tag-div")
dom.className = "cm-tooltip-cursor"
EditorView.baseTheme({
".cm-tooltip-lint": {
width: "80%",
},
".cm-tooltip-cursor": {
border: "none",
padding: "5px",
borderRadius: "4px",
"& .cm-tooltip-arrow:before": {
borderTopColor: "#66b !important"
},
"& .cm-tooltip-arrow:after": {
borderTopColor: "transparent",
}
}
})
dom.textContent = text
return {dom}
}
}
}
return null;
})
let state = EditorState.create({
doc: /* ... */
extensions: [
/* ... */
editorTheme.of(theme),
wordHover
]
});
let view = new EditorView({
state,
/* ... */
});
}
And this is what it looks like at the moment with the dark mode and light mode:
Any ideas on how I should do this? Or is it something I’m doing wrong?
Thank you so much in advanced.