-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add keyboard shortcuts #965
Add keyboard shortcuts #965
Conversation
9850049
to
8f07bae
Compare
Codecov ReportBase: 62.31% // Head: 62.26% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #965 +/- ##
==========================================
- Coverage 62.31% 62.26% -0.06%
==========================================
Files 86 86
Lines 1937 1937
Branches 215 215
==========================================
- Hits 1207 1206 -1
Misses 695 695
- Partials 35 36 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good variable names and readability, but doing too much in one method. Would be better to break up methods for readability and maintainability
const highlightedText = currentText.slice(selectionStart, selectionEnd); | ||
const hasInsertedCharBefore = currentText.slice(selectionStart - insertedChar.length, selectionStart) === insertedChar; | ||
const hasInsertedCharAfter = currentText.slice(selectionEnd, selectionEnd + insertedChar.length) === insertedChar; | ||
if (hasInsertedCharBefore && hasInsertedCharAfter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a toggling being done here, this can be indicated in the private method name or in a comment. (Toggle bold/italics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @gycgabriel ,to add on I think another suggestion is to extract out this condition into another method/boolean variable e.g. 'alreadyFormatted' (Please go ahead and use another name if you prefer, I can't think of a good one 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestions @gycgabriel and @kkangs0226, i've abstracted this out into a private method
this.commentField.setValue( | ||
currentText.slice(0, selectionStart) + | ||
SPACE.repeat(spacesRemovedLeft) + | ||
insertedChar + | ||
highlightedTextTrimmed + | ||
insertedChar + | ||
SPACE.repeat(spacesRemovedRight) + | ||
currentText.slice(selectionEnd) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks readable, I like that variable names make sense
Please also rename your PRs with Caps in front, and ensure that your commit message meets the requirements. (e.g. full stop at end of line) |
@@ -69,6 +68,56 @@ export class CommentEditorComponent implements OnInit { | |||
this.commentField.setValidators([Validators.maxLength(this.maxLength)]); | |||
} | |||
|
|||
onKeyPress(event) { | |||
if (event.ctrlKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, mac users will want to use the command ⌘
key instead of ctrl. I think we should check for the user's OS and handle the ⌘+b
or ⌘+i
shortcuts.
I personally don't use a Mac so other developers can comment on this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, thanks for pointing it out @chunweii . Seems like we can use metaKey
to handle the ⌘
key, you might want to include this in your code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, @chunweii, i've included it in the code, detecting either metaKey
or ctrlKey
press, as OS detection seems more complicated than I expected. I think it should be ok as metaKey
in windows refers to the windows key, and even so, testing on Chrome and Firefox on my windows machine, the browsers did not detect the metaKey
press. It seems that its been depreciated on Firefox at least (metaKey
is no longer supported on windows):
From https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work, I have left a few comments 😀
@@ -69,6 +68,56 @@ export class CommentEditorComponent implements OnInit { | |||
this.commentField.setValidators([Validators.maxLength(this.maxLength)]); | |||
} | |||
|
|||
onKeyPress(event) { | |||
if (event.ctrlKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, thanks for pointing it out @chunweii . Seems like we can use metaKey
to handle the ⌘
key, you might want to include this in your code.
const highlightedText = currentText.slice(selectionStart, selectionEnd); | ||
const hasInsertedCharBefore = currentText.slice(selectionStart - insertedChar.length, selectionStart) === insertedChar; | ||
const hasInsertedCharAfter = currentText.slice(selectionEnd, selectionEnd + insertedChar.length) === insertedChar; | ||
if (hasInsertedCharBefore && hasInsertedCharAfter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @gycgabriel ,to add on I think another suggestion is to extract out this condition into another method/boolean variable e.g. 'alreadyFormatted' (Please go ahead and use another name if you prefer, I can't think of a good one 😅)
return; | ||
} | ||
const currentText = this.commentField.value; | ||
const highlightedText = currentText.slice(selectionStart, selectionEnd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we are not considering trailing/leading spaces here, could we check for spaces here as well for checking whether it is already formatted? e.g. highlighted text' example ' with space before and after will not be considered 'formatted' in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good point @kkangs0226, i've added a private method to detect if the trimmed highlighted text is already formatted, and another method to handle that case
3852580
to
6b41416
Compare
6b41416
to
9b8d77a
Compare
hi @gycgabriel, @kkangs0226, @chunweii I've refactored this PR into smaller methods, as suggested, do take a look again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods shortened, and naming const are good making code very readable. Almost LGTM:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
hi @chunweii, i've added in the OS detection and tested it on my mac, with the help of these docs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I have pointed out seems to have been fixed, thanks for your work 👍 after @chunweii approves of the changes, we can proceed to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the small nitpick, LGTM 👍
There are some minor issues, but I don't think it is a big problem. For example, pressing ctrl+b followed by ctrl+i and ctrl+b will create **_**text**_**
. Also, trying to bold or italicize text across multiple lines may not work. But the github comment editor also has the same issues, and it is unlikely to be an inconvenience to students.
@@ -5,6 +5,7 @@ import * as DOMPurify from 'dompurify'; | |||
import { ErrorHandlingService } from '../../core/services/error-handling.service'; | |||
import { LoggingService } from '../../core/services/logging.service'; | |||
import { FILE_TYPE_SUPPORT_ERROR, getSizeExceedErrorMsg, SUPPORTED_FILE_TYPES, UploadService } from '../../core/services/upload.service'; | |||
const os = require('os'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this line since we are not using node js os
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah my bad, removed!
Good point raised, this seems like something we can work on. For example, detecting whether there are repeated characters within the highlighted text, rather than just the two ends of the string. |
@cedricongjh Do you think you can work on these changes in this PR? If not, we can create another issue for this and go ahead with merging this PR first as it is not critical at the moment. |
hi @kkangs0226, I think we should create another issue for this and go ahead with merging this, thanks |
Summary:
Fixes #823
Changes Made:
CATcher.3.4.2.-.CATcher-org_undefined.-.Google.Chrome.2022-07-12.03-26-14_Trim.mp4
Proposed Commit Message: