Skip to content

Commit

Permalink
docs: update for v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Sep 17, 2023
1 parent b20b199 commit 44e2a5f
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ https://prism-code-editor.netlify.app
- [Creating a theme](#creating-a-theme)
- [Language specific behavior](#language-specific-behavior)
- [Adding languages](#adding-languages)
- [Tooltips](#tooltips)
- [Overscroll](#overscroll)
- [Editing key commands](#editing-key-commands)
- [Web components](#web-components)
- [Prism plugin support](#prism-plugin-support)
Expand Down Expand Up @@ -431,14 +433,40 @@ languages.whatever = {
([start, end], value) => /\[]|\(\)|{}/.test(code[start - 1] + code[end])
],
autoCloseTags([start, end, direction], value) {
// Function called when the user types ">".
// Intended to auto close tags.
// If a string is returned, it will get inserted
// behind the cursor after a 100ms delay.
// Function called when the user types ">", intended to auto close tags.
// If a string is returned, it will get inserted behind the cursor.
}
}
```

## Tooltips

There's a utility to display tooltips above or below the cursor that can be imported from `prism-code-editor/tooltips`.

```typescript
const addTooltip = (editor: PrismEditor, element: HTMLElement, fixedWidth?: boolean): [ShowTooltip, HideTooltip]

const [show, hide] = addTooltip(editor, element)
```

- `editor`: The editor you want the tooltip to be associated with.
- `element`: The element for your tooltip.
- `fixedWidth`: If false, the tooltip will shrink instead of getting offset to the left if there's not enough space to the right of the cursor. Defaults to `true`.

You must add the `cursorPosition` extension to the editor before calling the `show` function.

If you want the tooltip to always be visible when the user scrolls horizontally, add `position: sticky` along with the `left` and/or `right` CSS properties to your tooltip.

## Overscroll

```javascript
import { addOverscroll, removeOverscroll } from "prism-code-editor/tooltips"

addOverscroll(editor)
```

This will allow users to scroll until the last line is at the top of the editor.

## Editing key commands

Editing key commands is as simple as mutating the `keyCommandMap` for the editor. If you're adding the default commands to the editor, be sure to mutate the command map after adding that extension.
Expand Down

0 comments on commit 44e2a5f

Please sign in to comment.