Skip to content

Commit 6893462

Browse files
authored
fix(inline-tools): inline tools shortcuts now works in read-only mode (#2891)
* fix(inline-tools): inline tools shortcuts now works in read-only mode * use ubuntu-20.04 instead of latest
1 parent d9f301f commit 6893462

File tree

10 files changed

+75
-17
lines changed

10 files changed

+75
-17
lines changed

.github/workflows/bump-version-on-merge-next.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Bump version on merge
22

3-
# Caution:
3+
# Caution:
44
# the use of "pull_request_target" trigger allows to successfully
55
# run workflow even when triggered from a fork. The trigger grants
66
# access to repo's secrets and gives write permission to the runner.
@@ -17,7 +17,7 @@ jobs:
1717
# If pull request was merged then we should check for a package version update
1818
check-for-no-version-changing:
1919
if: github.event.pull_request.merged == true
20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-20.04
2121
permissions:
2222
actions: write
2323
steps:

.github/workflows/create-a-release-draft.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Create a release draft
22

3-
# Caution:
3+
# Caution:
44
# the use of "pull_request_target" trigger allows to successfully
55
# run workflow even when triggered from a fork. The trigger grants
66
# access to repo's secrets and gives write permission to the runner.
@@ -17,7 +17,7 @@ jobs:
1717
# If pull request was merged then we should check for a package version update
1818
check-version-changing:
1919
if: github.event.pull_request.merged == true
20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-20.04
2121
permissions:
2222
actions: write
2323
steps:
@@ -113,7 +113,7 @@ jobs:
113113
asset_path: dist/editorjs.umd.js
114114
asset_name: editorjs.umd.js
115115
asset_content_type: application/javascript
116-
116+
117117
# Build and upload target Editor.js MJS build to release as artifact
118118
- name: Upload Release Asset
119119
uses: actions/upload-release-asset@v1
@@ -123,7 +123,7 @@ jobs:
123123
upload_url: ${{ steps.create_release.outputs.upload_url }}
124124
asset_path: dist/editorjs.mjs
125125
asset_name: editorjs.mjs
126-
asset_content_type: application/javascript
126+
asset_content_type: application/javascript
127127

128128
# Send a notification message
129129
- name: Send a message
@@ -132,4 +132,4 @@ jobs:
132132
webhook: ${{ secrets.CODEX_BOT_WEBHOOK_FRONTEND }}
133133
message: '🦥 [Draft release v${{ steps.package.outputs.version }}](${{ steps.create_release.outputs.html_url }}) for package [${{ steps.package.outputs.name }}](${{ steps.package.outputs.npmjs-link }}) has been created. Add changelog and publish it!'
134134
parse_mode: 'markdown'
135-
disable_web_page_preview: true
135+
disable_web_page_preview: true

.github/workflows/cypress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
matrix:
99
browser: [firefox, chrome, edge]
1010

11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
steps:
1313
- uses: actions/setup-node@v3
1414
with:

.github/workflows/eslint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [pull_request]
55
jobs:
66
lint:
77
name: ESlint
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-20.04
99
steps:
1010
- uses: actions/checkout@v2
1111

.github/workflows/publish-package-to-npm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
publish:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-20.04
1111
steps:
1212
# Checkout to target branch
1313
- uses: actions/checkout@v4
@@ -62,4 +62,4 @@ jobs:
6262
webhook: ${{ secrets.CODEX_BOT_NOTIFY_EDITORJS_PUBLIC_CHAT }}
6363
message: '📦 [${{ steps.package.outputs.name }} ${{ steps.package.outputs.version }}](${{ env.GITHUB_LINK }}) was published'
6464
parse_mode: 'markdown'
65-
disable_web_page_preview: true
65+
disable_web_page_preview: true

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 2.31.0
44

55
- `New` - Inline tools (those with `isReadOnlySupported` specified) can now be used in read-only mode
6+
- `New` - Inline tools (those with `isReadOnlySupported` specified) shortcuts now work in read-only mode
67
- `Improvement` - Block manager passes target tool config to the `conversionConfig.import` method on conversion
78
- `Fix` - Fix selection of first block in read-only initialization with "autofocus=true"
89
- `Fix` - Incorrect caret position after blocks merging in Safari

src/components/modules/toolbar/inline.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
549549

550550
this.popover?.activateItemByName(toolName);
551551
},
552-
on: this.Editor.UI.nodes.redactor,
552+
/**
553+
* We need to bind shortcut to the document to make it work in read-only mode
554+
*/
555+
on: document,
553556
});
554557
}
555558

src/components/utils/shortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ShortcutData {
2828
/**
2929
* Element handler should be added for
3030
*/
31-
on: HTMLElement;
31+
on: HTMLElement | Document;
3232
}
3333

3434
/**

test/cypress/tests/ui/InlineToolbar.cy.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
import Header from '@editorjs/header';
3-
import type { MenuConfig } from '../../../../types/tools';
2+
import type { InlineTool, MenuConfig } from '../../../../types/tools';
3+
import { createEditorWithTextBlocks } from '../../support/utils/createEditorWithTextBlocks';
44

55
describe('Inline Toolbar', () => {
66
describe('Separators', () => {
@@ -174,4 +174,58 @@ describe('Inline Toolbar', () => {
174174
.should('have.attr', 'data-item-name', 'test-tool');
175175
});
176176
});
177+
178+
describe('Shortcuts', () => {
179+
it('should work in read-only mode', () => {
180+
const toolSurround = cy.stub().as('toolSurround');
181+
182+
/* eslint-disable jsdoc/require-jsdoc */
183+
class Marker implements InlineTool {
184+
public static isInline = true;
185+
public static shortcut = 'CMD+SHIFT+M';
186+
public static isReadOnlySupported = true;
187+
public render(): MenuConfig {
188+
return {
189+
icon: 'm',
190+
title: 'Marker',
191+
onActivate: () => {
192+
toolSurround();
193+
},
194+
};
195+
}
196+
}
197+
/* eslint-enable jsdoc/require-jsdoc */
198+
199+
createEditorWithTextBlocks([
200+
'some text',
201+
], {
202+
tools: {
203+
marker: Marker,
204+
},
205+
readOnly: true,
206+
});
207+
208+
cy.get('[data-cy=editorjs]')
209+
.find('.ce-paragraph')
210+
.selectText('text');
211+
212+
cy.wait(300);
213+
214+
cy.document().then((doc) => {
215+
doc.dispatchEvent(new KeyboardEvent('keydown', {
216+
bubbles: true,
217+
cancelable: true,
218+
key: 'M',
219+
code: 'KeyM',
220+
keyCode: 77,
221+
which: 77,
222+
metaKey: true,
223+
shiftKey: true,
224+
}));
225+
});
226+
227+
cy.get('@toolSurround').should('have.been.called');
228+
});
229+
});
177230
});
231+

test/cypress/tests/utils/popover.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ describe('Popover', () => {
881881
.should('exist');
882882
});
883883

884-
it.only('shoould support i18n in nested popover', () => {
884+
it('shoould support i18n in nested popover', () => {
885885
/**
886886
*
887887
*/
@@ -1076,7 +1076,7 @@ describe('Popover', () => {
10761076
.should('exist');
10771077
});
10781078

1079-
it.only('should allow to reach nested popover via keyboard', () => {
1079+
it('should allow to reach nested popover via keyboard', () => {
10801080
cy.createEditor({
10811081
tools: {
10821082
header: {

0 commit comments

Comments
 (0)