Skip to content
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

copy_and_paste: Fix CSS selector injection bug, convert module to TypeScript #30091

Merged
merged 3 commits into from
May 14, 2024

Conversation

andersk
Copy link
Member

@andersk andersk commented May 14, 2024

No description provided.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
Signed-off-by: Anders Kaseorg <anders@zulip.com>
@andersk andersk added integration review Added by maintainers when a PR may be ready for integration. area: typescript migration Issues for migrating Zulip to TypeScript labels May 14, 2024
Signed-off-by: Anders Kaseorg <anders@zulip.com>
@@ -293,63 +313,71 @@ function get_end_tr_from_endc($endc) {
// we can use the last message from the previous recipient_row.
if ($endc.parents(".message_header").length > 0) {
const $overflow_recipient_row = $endc.parents(".recipient_row").first();
return $overflow_recipient_row.prev(".recipient_row").last(".message_row");
return $overflow_recipient_row.prev(".recipient_row").last();
Copy link
Sponsor Member

@timabbott timabbott May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a functional change? I guess not, both because last ignores parameters and because the last item in a recipient_row is always a message_row; I'm just not sure that's guaranteed to be an invariant.

        <div class="recipient_row" id="{{message_group_id}}">
            {{> recipient_row use_match_properties=../use_match_properties}}
            {{#each message_containers}}
                {{#with this}}
                {{> single_message use_match_properties=../../use_match_properties message_list_id=../../message_list_id}}
                {{/with}}
            {{/each}}
        </div>

But probably we meant to write .filter(".message_row").last()?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is really quite confusing -- the comments think it's getting a message_row, but it's always been getting a recipient_row

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know what the intention was, but the jQuery .last() method does not accept any arguments.

Copy link
Sponsor Member

@timabbott timabbott May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll let @N-Shar-ma clean this up, since this is ancient code but I think she has a good test setup for verifying changes. The old code is quite clearly wrong but it's not clear what is the correct version... and this doesn't regress anything.

@@ -265,7 +285,7 @@ export function analyze_selection(selection) {
};
}

function get_end_tr_from_endc($endc) {
function get_end_tr_from_endc($endc: JQuery<Node>): JQuery {
if ($endc.attr("id") === "bottom_whitespace" || $endc.attr("id") === "compose_close") {
// If the selection ends in the bottom whitespace, we should
// act as though the selection ends on the final message.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here looks buggy as well; $(".message_row").last(); does not filter to the currently visible message list, if the combined feed is still present/invisible.

@N-Shar-ma perhaps you can do a follow-up PR fixing this and the other apparent logic bug this TS migration reveals? I don't think there's any regressions in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #30096

@timabbott timabbott merged commit 4d407c6 into zulip:main May 14, 2024
14 checks passed
@andersk andersk deleted the copy_and_paste.ts branch May 14, 2024 21:13
N-Shar-ma added a commit to N-Shar-ma/zulip that referenced this pull request May 14, 2024
Fixed 2 bugs in the detection of the last message row copied. This fixes
the issue where when the mouse was released on the message header after
copying multiple messages, the pasted text was not formatted correctly.

Follow up to zulip#30091.
timabbott pushed a commit that referenced this pull request May 15, 2024
Fixed 2 bugs in the detection of the last message row copied. This fixes
the issue where when the mouse was released on the message header after
copying multiple messages, the pasted text was not formatted correctly.

Follow up to #30091.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: typescript migration Issues for migrating Zulip to TypeScript integration review Added by maintainers when a PR may be ready for integration. size: XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants