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

Table widget: reordering rows and columns #11271

Merged
merged 12 commits into from
Oct 17, 2024

Conversation

farmaazon
Copy link
Contributor

@farmaazon farmaazon commented Oct 8, 2024

Pull Request Description

Fixes #10759

Screencast.From.2024-10-14.13-51-24.webm

Important Notes

In this task, I also fixed some badly looking spacing after editing vector.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.

@farmaazon farmaazon added x-new-feature Type: new feature request -gui labels Oct 8, 2024
@farmaazon farmaazon self-assigned this Oct 8, 2024
@farmaazon farmaazon marked this pull request as ready for review October 14, 2024 11:52
Copy link
Contributor

@kazcw kazcw left a comment

Choose a reason for hiding this comment

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

The idea behind autospaced nodes (.whitespace = undefined) is when editing, we never set the spacing of a node based on the spacing of another node; instead, we set nodes to autospaced, and apply spacing-matching logic when printing. This serves two purposes:

  • It simplifies editing operations, separating them from the concrete syntax logic.
  • It is the only way to ensure spacing remains consistent when Y.Js merges concurrent edits. Although in this case it is only aesthetic, spacing consistency is often important for semantics--so even though this type of merge conflict may be rare, handling it correctly is important.

In this case, we could change the preferUnspaced(value) in the isFirst branch of Vector.concreteChildren to preferSpacedIf(value, close.whitespace); then, during edit operations we need only ensure that:

  • Before the operation, the first element is autospaced.
  • After the operation, the first element is autospaced.

@@ -11,6 +11,7 @@ import { assert } from '@/util/assert'
import { Ast } from '@/util/ast'
import { GetContextMenuItems, GetMainMenuItems } from 'ag-grid-enterprise'
import { expect, test, vi } from 'vitest'
import { m } from 'vitest/dist/reporters-yx5ZTtEV.js'
Copy link
Contributor

Choose a reason for hiding this comment

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

Added by IDE?

Comment on lines 2499 to 2504
// Spacing around opening brackets should be preserved, as it's more natural (see tests).
const firstSpacing = elements[0]?.value?.whitespace
elements.splice(start, deletedCount)
if (start === 0 && firstSpacing != null && elements[0]?.value != null) {
elements[0].value.whitespace = firstSpacing
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would instead:

  • Map the new elements to all be autospaced--they should fit into the target vector rather than bring their spacing.
  • After the splice call, unconditionally set the first element (if any) to autospaced.

Comment on lines 2521 to 2538
// Restore/automate spacing to look make array look more natural.
// 1. Keep the spacing after opening bracket
if (
(toIndex === 0 || fromIndex === 0) &&
firstSpacing != null &&
elements[0]?.value != null
) {
elements[0].value.whitespace = firstSpacing
}
// 2. If the first element was moved, automate the spacing (often from no-space to
// single-space)
if (fromIndex === 0 && toIndex !== 0 && elements[toIndex]?.value != null) {
elements[toIndex].value.whitespace = undefined
}
// 3. If the first element was shifted by inserting element before, also automate its spacing
if (toIndex === 0 && elements[1]?.value != null) {
elements[1].value.whitespace = undefined
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just:

  • Before splicing, set the first element to autospaced.
  • After splicing, set the first element to autospaced.

Comment on lines +2545 to +2552
// Spacing around opening brackets should be preserved, as it's more natural (see tests).
const firstSpacing = elements[0]?.value?.whitespace
const filtered = elements.filter(
element => element.value && predicate(this.module.get(element.value.node)),
)
if (firstSpacing != null && filtered[0]?.value != null) {
filtered[0].value.whitespace = firstSpacing
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just set the first element (after filtering) to autospaced unconditionally.

@farmaazon farmaazon requested a review from kazcw October 16, 2024 08:09
@farmaazon
Copy link
Contributor Author

I updated the "autospacing" of elements, but a bit differently: just we make sure, that inserted/moved elements are autospaced, and any element directly after their new/former spots.

@farmaazon farmaazon added the CI: Ready to merge This PR is eligible for automatic merge label Oct 16, 2024
@mergify mergify bot merged commit a45e233 into develop Oct 17, 2024
37 checks passed
@mergify mergify bot deleted the wip/farmaazon/table-widget-reordering branch October 17, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-gui CI: Ready to merge This PR is eligible for automatic merge x-new-feature Type: new feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table Editor widget: reordering columns and rows
2 participants