Commit 40522538 authored by Nathan Friend's avatar Nathan Friend

Stop applying Ctrl markdown shortcuts on Mac

This commit updates the Markdown editor keyboard shortcuts to only apply
the appropriate variant (Ctrl vs ⌘) for the current platform.
parent 471ab1c4
...@@ -143,7 +143,7 @@ export default { ...@@ -143,7 +143,7 @@ export default {
:button-title=" :button-title="
sprintf(s__('MarkdownEditor|Add bold text (%{modifierKey}B)'), { modifierKey }) sprintf(s__('MarkdownEditor|Add bold text (%{modifierKey}B)'), { modifierKey })
" "
:shortcuts="['command+b', 'ctrl+b']" shortcuts="mod+b"
icon="bold" icon="bold"
/> />
<toolbar-button <toolbar-button
...@@ -151,7 +151,7 @@ export default { ...@@ -151,7 +151,7 @@ export default {
:button-title=" :button-title="
sprintf(s__('MarkdownEditor|Add italic text (%{modifierKey}I)'), { modifierKey }) sprintf(s__('MarkdownEditor|Add italic text (%{modifierKey}I)'), { modifierKey })
" "
:shortcuts="['command+i', 'ctrl+i']" shortcuts="mod+i"
icon="italic" icon="italic"
/> />
<toolbar-button <toolbar-button
...@@ -207,7 +207,7 @@ export default { ...@@ -207,7 +207,7 @@ export default {
:button-title=" :button-title="
sprintf(s__('MarkdownEditor|Add a link (%{modifierKey}K)'), { modifierKey }) sprintf(s__('MarkdownEditor|Add a link (%{modifierKey}K)'), { modifierKey })
" "
:shortcuts="['command+k', 'ctrl+k']" shortcuts="mod+k"
icon="link" icon="link"
/> />
</div> </div>
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
.md-header-toolbar.active .md-header-toolbar.active
= markdown_toolbar_button({ icon: "bold", = markdown_toolbar_button({ icon: "bold",
data: { "md-tag" => "**", "md-shortcuts": '["command+b","ctrl+b"]' }, data: { "md-tag" => "**", "md-shortcuts": '["mod+b"]' },
title: sprintf(s_("MarkdownEditor|Add bold text (%{modifier_key}B)") % { modifier_key: modifier_key }) }) title: sprintf(s_("MarkdownEditor|Add bold text (%{modifier_key}B)") % { modifier_key: modifier_key }) })
= markdown_toolbar_button({ icon: "italic", = markdown_toolbar_button({ icon: "italic",
data: { "md-tag" => "_", "md-shortcuts": '["command+i","ctrl+i"]' }, data: { "md-tag" => "_", "md-shortcuts": '["mod+i"]' },
title: sprintf(s_("MarkdownEditor|Add italic text (%{modifier_key}I)") % { modifier_key: modifier_key }) }) title: sprintf(s_("MarkdownEditor|Add italic text (%{modifier_key}I)") % { modifier_key: modifier_key }) })
= markdown_toolbar_button({ icon: "quote", data: { "md-tag" => "> ", "md-prepend" => true }, title: _("Insert a quote") }) = markdown_toolbar_button({ icon: "quote", data: { "md-tag" => "> ", "md-prepend" => true }, title: _("Insert a quote") })
= markdown_toolbar_button({ icon: "code", data: { "md-tag" => "`", "md-block" => "```" }, title: _("Insert code") }) = markdown_toolbar_button({ icon: "code", data: { "md-tag" => "`", "md-block" => "```" }, title: _("Insert code") })
= markdown_toolbar_button({ icon: "link", = markdown_toolbar_button({ icon: "link",
data: { "md-tag" => "[{text}](url)", "md-select" => "url", "md-shortcuts": '["command+k","ctrl+k"]' }, data: { "md-tag" => "[{text}](url)", "md-select" => "url", "md-shortcuts": '["mod+k"]' },
title: sprintf(s_("MarkdownEditor|Add a link (%{modifier_key}K)") % { modifier_key: modifier_key }) }) title: sprintf(s_("MarkdownEditor|Add a link (%{modifier_key}K)") % { modifier_key: modifier_key }) })
= markdown_toolbar_button({ icon: "list-bulleted", data: { "md-tag" => "- ", "md-prepend" => true }, title: _("Add a bullet list") }) = markdown_toolbar_button({ icon: "list-bulleted", data: { "md-tag" => "- ", "md-prepend" => true }, title: _("Add a bullet list") })
......
---
title: Stop applying Ctrl keyboard shortcuts inside Markdown editors on Mac
merge_request: 42239
author:
type: fixed
...@@ -6,6 +6,10 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do ...@@ -6,6 +6,10 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:is_mac) { page.evaluate_script('navigator.platform').include?('Mac') }
let(:modifier_key) { is_mac ? :command : :control }
let(:other_modifier_key) { is_mac ? :control : :command }
before do before do
project.add_developer(user) project.add_developer(user)
...@@ -16,7 +20,7 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do ...@@ -16,7 +20,7 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do
wait_for_requests wait_for_requests
end end
shared_examples 'keyboard shortcuts for modifier key' do shared_examples 'keyboard shortcuts' do
it 'bolds text when <modifier>+B is pressed' do it 'bolds text when <modifier>+B is pressed' do
type_and_select('bold') type_and_select('bold')
...@@ -57,17 +61,29 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do ...@@ -57,17 +61,29 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do
end end
end end
shared_examples 'keyboard shortcuts for implementation' do shared_examples 'no side effects' do
context 'Ctrl key' do it 'does not bold text when <other modifier>+B is pressed' do
let(:modifier_key) { :control } type_and_select('bold')
markdown_field.send_keys([@other_modifier_key, 'b'])
expect(markdown_field.value).not_to eq('**bold**')
end
it 'does not italicize text when <other modifier>+I is pressed' do
type_and_select('italic')
markdown_field.send_keys([@other_modifier_key, 'i'])
it_behaves_like 'keyboard shortcuts for modifier key' expect(markdown_field.value).not_to eq('_italic_')
end end
context '⌘ key' do it 'does not link text when <other modifier>+K is pressed' do
let(:modifier_key) { :command } type_and_select('link')
markdown_field.send_keys([@other_modifier_key, 'k'])
it_behaves_like 'keyboard shortcuts for modifier key' expect(markdown_field.value).not_to eq('[link](url)')
end end
end end
...@@ -76,7 +92,8 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do ...@@ -76,7 +92,8 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do
let(:markdown_field) { find_field('Release notes') } let(:markdown_field) { find_field('Release notes') }
let(:non_markdown_field) { find_field('Release title') } let(:non_markdown_field) { find_field('Release title') }
it_behaves_like 'keyboard shortcuts for implementation' it_behaves_like 'keyboard shortcuts'
it_behaves_like 'no side effects'
end end
context 'Haml markdown editor' do context 'Haml markdown editor' do
...@@ -84,7 +101,8 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do ...@@ -84,7 +101,8 @@ RSpec.describe 'Markdown keyboard shortcuts', :js do
let(:markdown_field) { find_field('Description') } let(:markdown_field) { find_field('Description') }
let(:non_markdown_field) { find_field('Title') } let(:non_markdown_field) { find_field('Title') }
it_behaves_like 'keyboard shortcuts for implementation' it_behaves_like 'keyboard shortcuts'
it_behaves_like 'no side effects'
end end
def type_and_select(text) def type_and_select(text)
......
...@@ -63,9 +63,9 @@ describe('Shortcuts', () => { ...@@ -63,9 +63,9 @@ describe('Shortcuts', () => {
// Get all shortcuts specified with md-shortcuts attributes in the fixture. // Get all shortcuts specified with md-shortcuts attributes in the fixture.
// `shortcuts` will look something like this: // `shortcuts` will look something like this:
// [ // [
// [ 'command+b', 'ctrl+b' ], // [ 'mod+b' ],
// [ 'command+i', 'ctrl+i' ], // [ 'mod+i' ],
// [ 'command+k', 'ctrl+k' ] // [ 'mod+k' ]
// ] // ]
shortcuts = $('.edit-note .js-md') shortcuts = $('.edit-note .js-md')
.map(function getShortcutsFromToolbarBtn() { .map(function getShortcutsFromToolbarBtn() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment