Skip to content

fix: distribute multi-line clipboard per selection in column mode paste - #641

Open
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/ut-scan-20261010
Open

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/ut-scan-20261010

Conversation

@add-uos

@add-uos add-uos commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When in column-edit mode (Alt + drag, i.e. the 列模式 column selection), pasting a multi-line clipboard inserted the whole clipboard text into every column selection, with no per-line distribution logic in InsertTextUndoCommand::redo() (src/editor/inserttextundocommand.cpp).

Example: 3 column selections selecting XY on 3 lines, clipboard AAA\nBBB\nCCC — before this change:

aaaaAAA          <- selection 1 gets the ENTIRE clipboard
BBB
CCCbbbb
ccccAAA          <- selection 2 gets the ENTIRE clipboard (duplicated)
BBB
CCCdddd
eeeeAAA          <- selection 3 gets the ENTIRE clipboard (duplicated)
BBB
CCCeeee

9 lines of duplicated content instead of the expected 3 lines distributed one per selection. Single-line clipboard paste was already correct.

Fix

In the multi-selection constructor of InsertTextUndoCommand, when the clipboard text has the same number of lines as the column selections, store one clipboard line per selection (ColumnReplaceNode::insertedText); redo()/undo()/columnOffset accounting then use the per-selection inserted text.

  • This matches mainstream editors' column/multi-cursor paste semantics (VS Code, Sublime, Notepad++ distribute lines when the counts match; none duplicate the whole clipboard at every cursor).
  • It is also the natural round-trip of this project's own column-mode copy, which joins per-selection texts with \n (dtextedit.cpp).
  • When the line count differs from the selection count, the previous whole-text-per-selection behavior is kept (same as VS Code's mismatch fallback), so single-line clipboard and mismatch cases are unchanged.
  • undo() now restores each selection by its actual inserted text size, so undo/redo round-trips stay exact.

Verification

Standalone runtime test driving the actual command on a 3-line document with column selections: matched-count paste now yields aaaaAAAbbbb / ccccBBBdddd / eeeeCCCeeee; CRLF clipboards normalize then distribute; mismatch / single-line / zero-width-cursor cases unchanged; undo restores the original document exactly in all cases. Affected translation unit compiles against Qt6/DTK6.

Found by the unit-test / PMS-scan source-defect triage process (由单元测试/PMS 扫描缺陷甄别流程发现). No PMS/Issue number — behavior-observation item, fix direction aligned with mainstream editor semantics.

Summary by Sourcery

Fix column-mode multi-line paste to distribute matching clipboard lines across selections while keeping undo and redo behavior exact.

Bug Fixes:

  • Distribute multi-line clipboard content across column selections when the clipboard line count matches the number of selections, preventing duplicated pasted content.

Enhancements:

  • Preserve exact per-selection text lengths during column-mode paste redo and undo operations.
  • Retain the existing whole-text insertion behavior for single-line and line-count-mismatch clipboard pastes.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 6 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Column-mode paste now distributes a normalized multi-line clipboard one line per selection when line and selection counts match, while retaining whole-text fallback semantics otherwise. Replacement state and undo/redo bookkeeping use per-selection text lengths to preserve cursor positioning and exact restoration; package metadata is updated for the release.

Sequence diagram for column-mode distributed paste

sequenceDiagram
    participant Clipboard
    participant InsertTextUndoCommand
    participant ColumnSelections
    participant Document

    Clipboard->>InsertTextUndoCommand: InsertTextUndoCommand(selections, clipboardText)
    InsertTextUndoCommand->>InsertTextUndoCommand: replace("\\r\\n", "\\n")
    InsertTextUndoCommand->>InsertTextUndoCommand: split(QLatin1Char('\\n'))
    alt line count matches selection count and is greater than one
        InsertTextUndoCommand->>ColumnSelections: store lines.at(i) in insertedText
    else counts differ or clipboard is single-line
        InsertTextUndoCommand->>ColumnSelections: store whole clipboard in insertedText
    end
    InsertTextUndoCommand->>Document: redo()
    loop each column selection
        InsertTextUndoCommand->>Document: insertText(insertedText)
        InsertTextUndoCommand->>InsertTextUndoCommand: update columnOffset
    end
    InsertTextUndoCommand->>Document: undo()
    loop each column selection
        InsertTextUndoCommand->>Document: restore originText using insertedText.size()
    end
Loading

File-Level Changes

Change Details Files
Distribute matched multi-line clipboard content across column selections while preserving the existing fallback behavior for unmatched line counts.
  • Normalize and split clipboard text into lines, enabling distribution only when multiple lines exactly match the selection count.
  • Store per-selection inserted text in each replacement node, using one line per selection or the full clipboard for fallback cases.
src/editor/inserttextundocommand.cpp
src/editor/inserttextundocommand.h
Make redo, undo, selection positioning, and document offset tracking use each selection’s actual inserted text.
  • Replace hard-coded full-clipboard sizing with per-selection inserted-text sizing during replacement and cursor reconstruction.
  • Update column offset accumulation so subsequent selections remain correctly positioned after variable-length inserts.
src/editor/inserttextundocommand.cpp
Update package metadata for the fixed release.
  • Bump the Linglong package version.
  • Add the release entry to the Debian changelog.
linglong.yaml
debian/changelog

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 6.5.58
EXISTED: no
DISTRIBUTION: unstable

@add-uos
add-uos force-pushed the fix/ut-scan-20261010 branch from f517911 to 2ea1440 Compare October 10, 2026 05:27
When pasting with column (Alt) selections and the clipboard text has
the same number of lines as the selections, insert one clipboard line
per selection, matching mainstream editors (VS Code, Sublime,
Notepad++). Previously the whole multi-line text was inserted into
every selection, duplicating the entire clipboard at each cursor.
When the line count differs from the selection count, the previous
whole-text-per-selection behavior is kept.

列编辑模式下粘贴与列选区数量一致的多行剪贴板时,按行分发到各列选区,
对齐主流编辑器(VS Code/Sublime/Notepad++)的列模式粘贴语义;此前整段
文本会被原样插入每个选区,导致内容在每个选区整段重复。行数与选区数
不一致时保持原有整段插入行为,撤销/重做按各选区实际插入文本还原。

Log: 修复列编辑粘贴多行剪贴板时内容在每个选区整段重复的问题
Influence: 列编辑模式下粘贴多行剪贴板的行为
@add-uos
add-uos force-pushed the fix/ut-scan-20261010 branch from f4439ef to 3fbf315 Compare October 10, 2026 05:35
@deepin-bot

deepin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.6
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #670

@deepin-bot

deepin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.7
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #675

@deepin-bot

deepin-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.8
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #678

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