# Tooltip possible?

**URL:** <https://discuss.codemirror.net/t/tooltip-possible/758>\
**Category:** Uncategorized\
**Created:** [May 25, 2016, 4:28pm UTC](https://discuss.codemirror.net/t/tooltip-possible/758 "2016-05-25T16:28:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![janoonk](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/j/57b2e6/32.png) [@janoonk](https://discuss.codemirror.net/u/janoonk)\
**Post date:** [May 25, 2016, 4:28pm UTC](https://discuss.codemirror.net/t/tooltip-possible/758/1 "2016-05-25T16:28:48Z")

</div>

Whats the best way to implement a tooltip? If a user types a SQL function for example **LOWER(**  
then I want to show a tooltip with the parameter(s), datatypes and a short description for example.  
Does CodeMirror already has this functionality?

---

<div class="post-metadata">

**Author:** ![janoonk](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/j/57b2e6/32.png) [@janoonk](https://discuss.codemirror.net/u/janoonk)\
**Post date:** [May 25, 2016, 4:42pm UTC](https://discuss.codemirror.net/t/tooltip-possible/758/2 "2016-05-25T16:42:51Z")

</div>

I probably should use Widget I guess.

To show a Widget you can use:

```
// create a node
var htmlNode =document.createElement("h1");
var text = document.createTextNode("Text or whatever");
htmlNode.appendChild(text)

// call this after you initialized the editor.
// the position must be like this {ch: YourCharecterNumber, line: YourLineNumber}
editor.addWidget({ch:1 , line: 1},htmlNode, true)

```

I can catch the ( key and check if the word before the ( is listed in the available SQL functions and then create the widget by doing some lookup in a SQL reference/documentation datastructure.  
I should then look for a ) keypress and then remove the Widget.  
If the SQL function has multiple parameters I should also check for a , and then make the current parameter bold.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 25, 2016, 7:59pm UTC](https://discuss.codemirror.net/t/tooltip-possible/758/3 "2016-05-25T19:59:44Z")

</div>

The recommended way, used for example in the Tern plugin, is to just use `charCoords` to position your own node over the editor.

---

<div class="post-metadata">

**Author:** ![janoonk](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/j/57b2e6/32.png) [@janoonk](https://discuss.codemirror.net/u/janoonk)\
**Post date:** [May 25, 2016, 9:57pm UTC](https://discuss.codemirror.net/t/tooltip-possible/758/4 "2016-05-25T21:57:56Z")

</div>

> [@marijn](#):
>
> charCoords

Ok thanks. Found the Tern demo at [CodeMirror: Tern Demo](https://codemirror.net/demo/tern.html)  
Managed to show a Widget just below the cursor when an SQL function is opened with ( and I can close the widget when ) is pressed.  
But I also want a short description of the SQL function when scrolling through the SQL function list.  
How do I position the tooltip just right from the sql show hint dropdown:

![](https://discuss.codemirror.net/uploads/default/original/1X/0c0cf5133f0dbfcb19a1c616142f72d78534c2fe.png)

Also the Tern demo inspired me to use a small icon indicating when it’s a table, column, sql function or keyword. Could you give me a hint where/how I could implement this?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 26, 2016, 7:54am UTC](https://discuss.codemirror.net/t/tooltip-possible/758/5 "2016-05-26T07:54:14Z")

</div>

Well, again, look at the tern addon. It implements both these features. The icons are pure CSS (which is a bit of a pain, but possible). The extra info for a selected hint is done by attaching a `"select"` handler to the completion object. See [the docs](http://codemirror.net/doc/manual.html#addon_show-hint) for show-hint.
