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
9d84846b
Unverified
Commit
9d84846b
authored
Feb 27, 2020
by
Lyza Gardner
Committed by
GitHub
Feb 27, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1847 from hypothesis/add-keyboad-save
Add save-with-key-combo support to `AnnotationOmega`
parents
86dabe49
e938f0f3
Changes
2
Show 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 @
9d84846b
...
@@ -99,10 +99,23 @@ function AnnotationOmega({
...
@@ -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
);
const
onToggleReplies
=
()
=>
setCollapsed
(
annotation
.
id
,
!
threadIsCollapsed
);
return
(
return
(
<
div
className
=
"annotation-omega"
>
/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */
<
div
className
=
"annotation-omega"
onKeyDown
=
{
onKeyDown
}
>
<
AnnotationHeader
<
AnnotationHeader
annotation
=
{
annotation
}
annotation
=
{
annotation
}
isEditing
=
{
isEditing
}
isEditing
=
{
isEditing
}
...
...
src/sidebar/components/test/annotation-omega-test.js
View file @
9d84846b
...
@@ -4,6 +4,7 @@ import { act } from 'preact/test-utils';
...
@@ -4,6 +4,7 @@ import { act } from 'preact/test-utils';
import
*
as
fixtures
from
'../../test/annotation-fixtures'
;
import
*
as
fixtures
from
'../../test/annotation-fixtures'
;
import
{
checkAccessibility
}
from
'../../../test-util/accessibility'
;
import
mockImportedComponents
from
'../../../test-util/mock-imported-components'
;
import
mockImportedComponents
from
'../../../test-util/mock-imported-components'
;
import
{
waitFor
}
from
'../../../test-util/wait'
;
import
{
waitFor
}
from
'../../../test-util/wait'
;
...
@@ -230,6 +231,79 @@ describe('AnnotationOmega', () => {
...
@@ -230,6 +231,79 @@ describe('AnnotationOmega', () => {
await
waitFor
(()
=>
fakeFlash
.
error
.
called
);
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', () => {
...
@@ -391,5 +465,21 @@ describe('AnnotationOmega', () => {
assert
.
isFalse
(
wrapper
.
find
(
'AnnotationActionBar'
).
exists
());
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