-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Compose Box: Implement formatting of channels and topics on paste #29302
base: main
Are you sure you want to change the base?
Conversation
0614e9a
to
b617509
Compare
@kuv2707 posted a next comment; as a side note, you should always post a top-level comment with a detailed update on the changes when you're ready for a next review on something; that habit is super helpful in getting timely reviews on you work. (GitHub doesn't notify anyone if you just push updates, so it's by chance that I came back to this PR today) |
Got it. |
f83920c
to
68629ae
Compare
@kuv2707 As @timabbott noted, you need to comment that your PR is ready for review here, not just on CZO. |
Works for me otherwise! I like how this feature feels. |
I haven't dealt with |
Oh I'm sorry, it slipped my mind. I'll be more cautious from now onwards. |
Added a commit which covers |
1009ef6
to
3527ff6
Compare
How are |
The stream and topic names are being extracted from them and then transformed. |
3527ff6
to
86a8e7d
Compare
|
OK, please make sure all of @timabbott 's comments above are addressed in replies, and then this PR should be ready for another review. |
I've addressed all the comments. The PR is ready for another review. |
86a8e7d
to
24f50be
Compare
web/src/copy_and_paste.js
Outdated
const init_cursor_pos = text_area.selectionStart; | ||
document.execCommand("insertText", false, text); | ||
const new_cursor_pos = text_area.selectionStart; | ||
text_area.setSelectionRange(init_cursor_pos, new_cursor_pos); |
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 use of execCommand
is I think deprecated? https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
In any case, our general policy is for any manipulation of the compose area use the compose_ui
module and its text-field-edit
library, and we should follow that here as well.
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.
Sure, I'll switch to that.
There were a few places in the codebase where execCommand
is still used.
4d13458
to
3f75458
Compare
3201f66
to
73126b9
Compare
@timabbott I have made the suggested changes. |
73126b9
to
790f023
Compare
@N-Shar-ma Can you review this PR? A review from you would be greatly helpful since this area has many contributions from you. |
790f023
to
319fbe0
Compare
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.
Have left a comment suggesting a refactor. Also, please specify in your commit subject line that its a stream / topic url in the same organisation. not just any url.
Otherwise LGTM and tests well!
web/src/copy_and_paste.js
Outdated
event.stopPropagation(); | ||
// Try to transform copied url text to #**stream>topic** syntax | ||
// if it is a valid url. | ||
const text = try_stream_topic_syntax_text(trimmed_paste_text, true); |
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.
Reading this block of code, without the definition of try_stream_topic_syntax_text
I wouldn't guess this function isn't pure (has side effects - inserting and selecting the url text). Also I'm not sure about testing this function as if it is pure.
I suggest keeping this a pure function which takes in the copied url and simply returns the stream topic syntax or null. The insertion of the copied url, followed by the stream topic syntax (if needed) should be done in another step.
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.
Sure, I've separated the text insertion part into a different function. Thanks for the input!
417300b
to
345918c
Compare
#30071 is a blocker for this PR since we need to check whether |
fc23d64
to
76f1db4
Compare
web/src/copy_and_paste.js
Outdated
if (syntax_text) { | ||
// It is a nice touch to get back the actual pasted url on undoing. | ||
add_text_and_select(trimmed_paste_text, $textarea); | ||
} |
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.
I think it'd be cleaner to insert the syntax text and return inside this block itself
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.
Done
Ttransforming valid stream/topic urls to the - A valid url contains a stream and optionally a topic but nothing else, and in that order. It must belong to the same origin as the Zulip server. The stream id present in the pasted url should correspond to an actual stream in the current server. - `near` links are not transformed. - Use-mention distinction is respected by not transforming a valid url if pasted using `Ctrl+Shift+V`. - No transformation occurs inside a code block. - On pressing `Ctrl+Z` after pasting, the actual pasted link is restored. Fixes zulip#29136
76f1db4
to
f8f9d1c
Compare
@timabbott This PR has been reviewed/approved by @N-Shar-ma . I just tested it as well. |
I'm not sure how we should handle pasting into the parens in a named link |
Currently, the user can I think we can check if we are inside the parens and decide not to format. @alya What do you think we should do? |
#**stream>topic**
syntax.Ctrl+Z
replaces the transformed link with the original pasted url.Fixes #29136
CZO discussion
Screenshots and screen captures
Sample input:
Compose box:
After being sent:
Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: