-
Notifications
You must be signed in to change notification settings - Fork 323
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
Conversation
…/table-widget-reordering
…/table-widget-reordering
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 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' |
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.
Added by IDE?
app/ydoc-shared/src/ast/tree.ts
Outdated
// 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 | ||
} |
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 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.
app/ydoc-shared/src/ast/tree.ts
Outdated
// 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 | ||
} |
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 would just:
- Before splicing, set the first element to autospaced.
- After splicing, set the first element to autospaced.
// 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 | ||
} |
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 would just set the first element (after filtering) to autospaced unconditionally.
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. |
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:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.