Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
198ef79a
Commit
198ef79a
authored
Jun 07, 2021
by
Enrique Alcantara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix list item keyboard shortcuts
parent
54fee676
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
36 deletions
+20
-36
app/assets/javascripts/content_editor/services/track_input_rules_and_shortcuts.js
...ontent_editor/services/track_input_rules_and_shortcuts.js
+6
-5
spec/frontend/content_editor/services/track_input_rules_and_shortcuts_spec.js
...t_editor/services/track_input_rules_and_shortcuts_spec.js
+14
-31
No files found.
app/assets/javascripts/content_editor/services/track_input_rules_and_shortcuts.js
View file @
198ef79a
import
{
mapValues
,
omit
}
from
'
lodash
'
;
import
{
mapValues
}
from
'
lodash
'
;
import
{
InputRule
}
from
'
prosemirror-inputrules
'
;
import
{
ENTER_KEY
,
BACKSPACE_KEY
}
from
'
~/lib/utils/keys
'
;
import
Tracking
from
'
~/tracking
'
;
...
...
@@ -36,15 +36,16 @@ const trackInputRulesAndShortcuts = (tiptapExtension) => {
addKeyboardShortcuts
()
{
const
shortcuts
=
this
.
parent
?.()
||
{};
const
{
name
}
=
this
;
/**
* We don’t want to track keyboard shortcuts
* that are not deliberately executed to create
* new types of content
*/
const
withoutEnterShortcut
=
omit
(
shortcuts
,
[
ENTER_KEY
,
BACKSPACE_KEY
]);
const
decorated
=
mapValues
(
withoutEnterShortcut
,
(
commandFn
,
shortcut
)
=>
trackKeyboardShortcut
(
name
,
commandFn
,
shortcut
),
const
dotNotTrackKeys
=
[
ENTER_KEY
,
BACKSPACE_KEY
];
const
decorated
=
mapValues
(
shortcuts
,
(
commandFn
,
shortcut
)
=>
dotNotTrackKeys
.
includes
(
shortcut
)
?
commandFn
:
trackKeyboardShortcut
(
name
,
commandFn
,
shortcut
),
);
return
decorated
;
...
...
spec/frontend/content_editor/services/track_input_rules_and_shortcuts_spec.js
View file @
198ef79a
...
...
@@ -5,11 +5,8 @@ import { Heading } from '@tiptap/extension-heading';
import
{
ListItem
}
from
'
@tiptap/extension-list-item
'
;
import
{
Paragraph
}
from
'
@tiptap/extension-paragraph
'
;
import
{
Text
}
from
'
@tiptap/extension-text
'
;
import
{
Editor
,
EditorContent
}
from
'
@tiptap/vue-2
'
;
import
{
mount
}
from
'
@vue/test-utils
'
;
import
{
nextTick
}
from
'
vue
'
;
import
{
Editor
}
from
'
@tiptap/vue-2
'
;
import
{
mockTracking
}
from
'
helpers/tracking_helper
'
;
import
{
extendedWrapper
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
KEYBOARD_SHORTCUT_TRACKING_ACTION
,
INPUT_RULE_TRACKING_ACTION
,
...
...
@@ -19,47 +16,33 @@ import trackInputRulesAndShortcuts from '~/content_editor/services/track_input_r
import
{
ENTER_KEY
,
BACKSPACE_KEY
}
from
'
~/lib/utils/keys
'
;
describe
(
'
content_editor/services/track_input_rules_and_shortcuts
'
,
()
=>
{
let
wrapper
;
let
trackingSpy
;
let
editor
;
let
trackedExtensions
;
const
HEADING_TEXT
=
'
Heading text
'
;
const
buildWrapper
=
()
=>
{
wrapper
=
extendedWrapper
(
mount
(
EditorContent
,
{
propsData
:
{
editor
,
},
}),
);
};
const
extensions
=
[
Document
,
Paragraph
,
Text
,
Heading
,
CodeBlockLowlight
,
BulletList
,
ListItem
];
beforeEach
(()
=>
{
trackingSpy
=
mockTracking
(
undefined
,
null
,
jest
.
spyOn
);
});
afterEach
(()
=>
{
wrapper
.
destroy
();
});
describe
(
'
given the heading extension is instrumented
'
,
()
=>
{
beforeEach
(()
=>
{
trackedExtensions
=
extensions
.
map
(
trackInputRulesAndShortcuts
);
editor
=
new
Editor
({
extensions
:
[
Document
,
Paragraph
,
Text
,
Heading
,
CodeBlockLowlight
,
BulletList
,
ListItem
,
].
map
(
trackInputRulesAndShortcuts
),
extensions
:
extensions
.
map
(
trackInputRulesAndShortcuts
),
});
});
beforeEach
(
async
()
=>
{
buildWrapper
();
await
nextTick
();
it
(
'
does not remove existing keyboard shortcuts
'
,
()
=>
{
extensions
.
forEach
((
extension
,
index
)
=>
{
const
originalShortcuts
=
Object
.
keys
(
extension
.
addKeyboardShortcuts
?.()
||
{});
const
trackedShortcuts
=
Object
.
keys
(
trackedExtensions
[
index
].
addKeyboardShortcuts
?.()
||
{},
);
expect
(
originalShortcuts
).
toEqual
(
trackedShortcuts
);
});
});
describe
(
'
when creating a heading using an keyboard shortcut
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment