Skip to content

Commit cd65d8c

Browse files
authoredMar 11, 2025
imrovement(flipper): allow to select next/prev line by shift arrows (#2918)
* fix: prevent flipper navigation when shift key is pressed * rm logs * feat: improve line selection with Shift + Up/Down * fix lint action * fix action * upd
1 parent 7399e55 commit cd65d8c

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed
 

‎.github/workflows/eslint.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v2
1111

12-
- name: Cache node modules
13-
uses: actions/cache@v1
12+
- name: Cache dependencies
13+
uses: actions/cache@v4
1414
with:
15-
path: node_modules
15+
path: ~/.npm
1616
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
1717
restore-keys: |
18-
${{ runner.OS }}-build-${{ env.cache-name }}-
19-
${{ runner.OS }}-build-
20-
${{ runner.OS }}-
18+
${{ runner.os }}-node-
2119
2220
- run: yarn
2321
- run: yarn lint

‎docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
- `Fix` - Fix the memory leak issue in `Shortcuts` class
1515
- `Fix` - Fix when / overides selected text outside of the editor
1616
- `DX` - Tools submodules removed from the repository
17+
- `Improvement` - Shift + Down/Up will allow to select next/previous line instead of Inline Toolbar flipping
18+
1719

1820
### 2.30.7
1921

‎src/components/flipper.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,23 @@ export default class Flipper {
199199
*
200200
* @param event - keydown event
201201
*/
202-
private onKeyDown = (event): void => {
202+
private onKeyDown = (event: KeyboardEvent): void => {
203203
const isReady = this.isEventReadyForHandling(event);
204204

205205
if (!isReady) {
206206
return;
207207
}
208208

209+
const isShiftKey = event.shiftKey;
210+
211+
/**
212+
* If shift key is pressed, do nothing
213+
* Allows to select next/prev lines of text using keyboard
214+
*/
215+
if (isShiftKey === true) {
216+
return;
217+
}
218+
209219
/**
210220
* Prevent only used keys default behaviour
211221
* (allows to navigate by ARROW DOWN, for example)

‎test/cypress/tests/utils/flipper.cy.ts

+39-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class SomePlugin {
4646
}
4747

4848
describe('Flipper', () => {
49-
it('should prevent plugins event handlers from being called while keyboard navigation', () => {
50-
const ARROW_DOWN_KEY_CODE = 40;
51-
const ENTER_KEY_CODE = 13;
49+
const ARROW_DOWN_KEY_CODE = 40;
50+
const ENTER_KEY_CODE = 13;
5251

52+
it('should prevent plugins event handlers from being called while keyboard navigation', () => {
5353
const sampleText = 'sample text';
5454

5555
cy.createEditor({
@@ -101,4 +101,40 @@ describe('Flipper', () => {
101101

102102
expect(SomePlugin.pluginInternalKeydownHandler).to.have.not.been.called;
103103
});
104+
105+
it('should not flip when shift key is pressed', () => {
106+
cy.createEditor({
107+
data: {
108+
blocks: [
109+
{
110+
type: 'paragraph',
111+
data: {
112+
text: 'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.',
113+
},
114+
},
115+
],
116+
},
117+
autofocus: true,
118+
});
119+
120+
cy.get('[data-cy=editorjs]')
121+
.get('.ce-paragraph')
122+
.as('paragraph')
123+
.selectTextByOffset([0, 10])
124+
.wait(200);
125+
126+
cy.get('@paragraph')
127+
.trigger('keydown', { keyCode: ARROW_DOWN_KEY_CODE,
128+
shiftKey: true });
129+
130+
// eslint-disable-next-line cypress/require-data-selectors
131+
cy.get('[data-cy="inline-toolbar"]')
132+
.get('.ce-popover--opened')
133+
.as('popover')
134+
.should('exist');
135+
136+
cy.get('@popover')
137+
.get('.ce-popover-item--focused')
138+
.should('not.exist');
139+
});
104140
});

0 commit comments

Comments
 (0)
Failed to load comments.