Skip to content

Fix increaseNestingLevel/decreaseNestingLevel for multi-item list selections#1319

Open
blshkv wants to merge 2 commits into
basecamp:mainfrom
blshkv:fix-nesting-level-multi-selection
Open

Fix increaseNestingLevel/decreaseNestingLevel for multi-item list selections#1319
blshkv wants to merge 2 commits into
basecamp:mainfrom
blshkv:fix-nesting-level-multi-selection

Conversation

@blshkv

@blshkv blshkv commented Jun 13, 2026

Copy link
Copy Markdown

Bug

When multiple list items are selected and the user clicks the indent or
outdent toolbar button (or presses Tab / Shift+Tab), only the first
selected item changes its nesting level. All other selected items are ignored.

Root cause

Both increaseNestingLevel() and decreaseNestingLevel() in
src/trix/models/composition.js call this.getBlock(), which always returns
the single block at locationRange[0].index — the start of the selection.
They then call this.document.replaceBlock() exactly once and return.

// before — only acts on the first block
increaseNestingLevel() {
  const block = this.getBlock()   // ← always locationRange[0].index
  if (!block) return
  return this.setDocument(this.document.replaceBlock(block, block.increaseNestingLevel()))
}

Fix

Iterate from locationRange[0].index to locationRange[1].index, applying
replaceBlock() for each block and threading the updated document through the
loop. A single setDocument() call is made at the end.

// after — covers every block in the selection
increaseNestingLevel() {
  const locationRange = this.getLocationRange()
  if (!locationRange) return
  let document = this.document
  for (let i = locationRange[0].index; i <= locationRange[1].index; i++) {
    const block = document.getBlockAtIndex(i)
    if (block) document = document.replaceBlock(block, block.increaseNestingLevel())
  }
  return this.setDocument(document)
}

The same change is applied to decreaseNestingLevel().

Tests

Two regression tests are added to src/test/system/list_formatting_test.js:

  • "increasing nesting level applies to all selected items" — creates a
    3-item bullet list, selects all three, clicks increaseNestingLevel, and
    asserts every block gained an extra nesting level.
  • "decreasing nesting level applies to all selected items" — creates a
    3-item list where items 2 and 3 are nested, selects both, clicks
    decreaseNestingLevel, and asserts both items returned to the top level.

Both methods called getBlock() which returns only the first block in the
selection (locationRange[0].index). When multiple list items were selected,
only the first item's nesting level changed.

Fix: iterate over every block index from locationRange[0].index to
locationRange[1].index, chaining replaceBlock() calls through the updated
document so all selected items are adjusted atomically before setDocument()
is called.

Add regression tests that select three items and assert all three change level.
Copilot AI review requested due to automatic review settings June 13, 2026 00:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Extend list nesting (indent/outdent) actions to operate over the current multi-block selection instead of only the active block, and add system tests to validate the selection-wide behavior.

Changes:

  • Update increaseNestingLevel / decreaseNestingLevel to iterate over the selection’s index range and apply the nesting transform per block.
  • Add system tests asserting nesting changes apply across multiple selected list items.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/trix/models/composition.js Applies nesting level changes across the selected range instead of a single block.
src/test/system/list_formatting_test.js Adds system tests for selection-wide increase/decrease nesting actions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/trix/models/composition.js Outdated
Comment thread src/trix/models/composition.js Outdated
Comment thread src/test/system/list_formatting_test.js Outdated
Comment thread src/trix/models/composition.js
- Skip the end block when selection ends at offset 0 (caret at block start
  means that block is not covered by the selection). Applied to both
  increaseNestingLevel and decreaseNestingLevel.
- Fix decrease-nesting test: item c starts at level 2, one decreaseNestingLevel
  call brings it to level 1, not level 0. Corrected expected blockAttributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants