Skip to content

Commit

Permalink
Update documentation for keyboard module
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jan 30, 2024
1 parent 41a96a5 commit 3a6985a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/website/content/docs/modules/keyboard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Handlers will be called with `this` bound to the keyboard instance and be passed

```js
quill.keyboard.addBinding({
key: 'B',
key: 'b',
shortKey: true
}, function(range, context) {
this.quill.formatText(range, 'bold', true);
Expand All @@ -24,7 +24,7 @@ quill.keyboard.addBinding({
// addBinding may also be called with one parameter,
// in the same form as in initialization
quill.keyboard.addBinding({
key: 'B',
key: 'b',
shortKey: true,
handler: function(range, context) {

Expand All @@ -36,21 +36,21 @@ If a modifier key is `false`, it is assumed to mean that modifier is not active.

```js
// Only b with no modifier will trigger
quill.keyboard.addBinding({ key: 'B' }, handler);
quill.keyboard.addBinding({ key: 'b' }, handler);

// Only shift+b will trigger
quill.keyboard.addBinding({ key: 'B', shiftKey: true }, handler);
quill.keyboard.addBinding({ key: ['b', 'B'], shiftKey: true }, handler);

// Either b or shift+b will trigger
quill.keyboard.addBinding({ key: 'B', shiftKey: null }, handler);
quill.keyboard.addBinding({ key: ['b', 'B'], shiftKey: null }, handler);

```

Multiple handlers may be bound to the same key and modifier combination. Handlers will be called synchronously, in the order they were bound. By default, a handler stops propagating to the next handler, unless it explicitly returns `true`.


```js
quill.keyboard.addBinding({ key: 'tab' }, function(range) {
quill.keyboard.addBinding({ key: 'Tab' }, function(range) {
// I will normally prevent handlers of the tab key
// Return true to let later handlers be called
return true;
Expand All @@ -67,7 +67,7 @@ Contexts enable further specification for handlers to be called only in particul
```js
// If the user hits backspace at the beginning of list or blockquote,
// remove the format instead delete any text
quill.keyboard.addBinding({ key: Keyboard.keys.BACKSPACE }, {
quill.keyboard.addBinding({ key: 'Backspace' }, {
collapsed: true,
format: ['blockquote', 'list'],
offset: 0
Expand All @@ -91,7 +91,7 @@ If `true`, called only if user's selection is on an empty line, `false` for a no

```js
// If the user hits enter on an empty list, remove the list instead
quill.keyboard.addBinding({ key: Keyboard.keys.ENTER }, {
quill.keyboard.addBinding({ key: 'Enter' }, {
empty: true, // implies collapsed: true and offset: 0
format: ['list']
}, function(range, context) {
Expand Down Expand Up @@ -174,15 +174,15 @@ const bindings = {
// There is no default binding named 'custom'
// so this will be added without overwriting anything
custom: {
key: 'B',
key: ['b', 'B'],
shiftKey: true,
handler: function(range, context) {
// Handle shift+b
}
},

list: {
key: 'backspace',
key: 'Backspace',
format: ['list'],
handler: function(range, context) {
if (context.offset === 0) {
Expand Down

0 comments on commit 3a6985a

Please sign in to comment.