Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
e938f0f3
Commit
e938f0f3
authored
Feb 26, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add save-with-key-combo support to `AnnotationOmega`
Resolves #1838
parent
5407f085
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
1 deletion
+104
-1
annotation-omega.js
src/sidebar/components/annotation-omega.js
+14
-1
annotation-omega-test.js
src/sidebar/components/test/annotation-omega-test.js
+90
-0
No files found.
src/sidebar/components/annotation-omega.js
View file @
e938f0f3
...
...
@@ -99,10 +99,23 @@ function AnnotationOmega({
}
};
// Allow saving of annotation by pressing CMD/CTRL-Enter
const
onKeyDown
=
event
=>
{
if
(
isEmpty
||
!
isEditing
)
{
return
;
}
if
((
event
.
metaKey
||
event
.
ctrlKey
)
&&
event
.
key
===
'Enter'
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
onSave
();
}
};
const
onToggleReplies
=
()
=>
setCollapsed
(
annotation
.
id
,
!
threadIsCollapsed
);
return
(
<
div
className
=
"annotation-omega"
>
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */
<
div
className
=
"annotation-omega"
onKeyDown
=
{
onKeyDown
}
>
<
AnnotationHeader
annotation
=
{
annotation
}
isEditing
=
{
isEditing
}
...
...
src/sidebar/components/test/annotation-omega-test.js
View file @
e938f0f3
...
...
@@ -4,6 +4,7 @@ import { act } from 'preact/test-utils';
import
*
as
fixtures
from
'../../test/annotation-fixtures'
;
import
{
checkAccessibility
}
from
'../../../test-util/accessibility'
;
import
mockImportedComponents
from
'../../../test-util/mock-imported-components'
;
import
{
waitFor
}
from
'../../../test-util/wait'
;
...
...
@@ -230,6 +231,79 @@ describe('AnnotationOmega', () => {
await
waitFor
(()
=>
fakeFlash
.
error
.
called
);
});
describe
(
'saving using shortcut-key combo'
,
()
=>
{
context
(
'in editing mode with text or tag content populated'
,
()
=>
{
beforeEach
(()
=>
{
// Put into editing mode by presence of draft, and add some `text`
// so that the annotation is not seen as "empty"
const
draft
=
fixtures
.
defaultDraft
();
draft
.
text
=
'bananas'
;
fakeStore
.
getDraft
.
returns
(
draft
);
});
it
(
'should save annotation if `CTRL+Enter` is typed'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
'.annotation-omega'
)
.
simulate
(
'keydown'
,
{
key
:
'Enter'
,
ctrlKey
:
true
});
assert
.
calledWith
(
fakeAnnotationsService
.
save
,
wrapper
.
props
().
annotation
);
});
it
(
'should save annotation if `META+Enter` is typed'
,
()
=>
{
const
wrapper
=
createComponent
();
wrapper
.
find
(
'.annotation-omega'
)
.
simulate
(
'keydown'
,
{
key
:
'Enter'
,
metaKey
:
true
});
assert
.
calledWith
(
fakeAnnotationsService
.
save
,
wrapper
.
props
().
annotation
);
});
it
(
'should not save annotation if `META+g` is typed'
,
()
=>
{
// i.e. don't save on non-"Enter" keys
const
wrapper
=
createComponent
();
wrapper
.
find
(
'.annotation-omega'
)
.
simulate
(
'keydown'
,
{
key
:
'g'
,
metaKey
:
true
});
assert
.
notCalled
(
fakeAnnotationsService
.
save
);
});
});
context
(
'empty or not in editing mode'
,
()
=>
{
it
(
'should not save annotation if not in editing mode'
,
()
=>
{
fakeStore
.
getDraft
.
returns
(
null
);
const
wrapper
=
createComponent
();
wrapper
.
find
(
'.annotation-omega'
)
.
simulate
(
'keydown'
,
{
key
:
'Enter'
,
metaKey
:
true
});
assert
.
notCalled
(
fakeAnnotationsService
.
save
);
});
it
(
'should not save annotation if content is empty'
,
()
=>
{
fakeStore
.
getDraft
.
returns
(
fixtures
.
defaultDraft
());
const
wrapper
=
createComponent
();
wrapper
.
find
(
'.annotation-omega'
)
.
simulate
(
'keydown'
,
{
key
:
'Enter'
,
ctrlKey
:
true
});
assert
.
notCalled
(
fakeAnnotationsService
.
save
);
});
});
});
});
});
...
...
@@ -391,5 +465,21 @@ describe('AnnotationOmega', () => {
assert
.
isFalse
(
wrapper
.
find
(
'AnnotationActionBar'
).
exists
());
});
it
(
'should pass a11y checks'
,
checkAccessibility
([
{
content
:
()
=>
createComponent
(),
},
{
name
:
'When editing'
,
content
:
()
=>
{
setEditingMode
(
true
);
return
createComponent
();
},
},
])
);
});
});
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