Skip to content

Comments

Fix long-press copy to include nested list options by copying visible list item text#36

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/vscode1757253437851
Closed

Fix long-press copy to include nested list options by copying visible list item text#36
Copilot wants to merge 2 commits intomainfrom
copilot/vscode1757253437851

Conversation

Copy link
Contributor

Copilot AI commented Sep 7, 2025

Problem

The long-press copy functionality for list items was using a brittle index-based lookup that caused issues with nested lists. The system relied on:

  • window.__APP_DATA__.listItems array (parsed markdown items)
  • data-list-index attributes assigned to each <li> element

This created a mismatch between the parsed markdown structure and the actual DOM NodeList, especially when questions contained nested options. As a result:

  • Top-level questions didn't copy their nested sub-options
  • Index mapping could be incorrect in some cases
  • The feature was unreliable for structured content like homework problems

Solution

Replaced the index-based approach with direct element text copying using element.innerText or element.textContent. This approach:

  • ✅ Copies the full visible text from the clicked <li> element
  • ✅ Naturally includes any nested sub-lists/options rendered in the DOM
  • ✅ Is robust to nested structures without relying on fragile index mapping
  • ✅ Preserves all existing notifications and error handling

Changes

Before:

async copyListContent(element) {
    const listIndex = parseInt(element.dataset.listIndex, 10);
    const listData = window.__APP_DATA__.listItems;
    const isValidIndex = !isNaN(listIndex) && listData && listIndex < listData.length && listData[listIndex];
    
    if (!isValidIndex) {
        await this.copyElementText(element);
        return;
    }
    
    const textToCopy = listData[listIndex].content;
    await this._copyToClipboard(textToCopy);
}

After:

async copyListContent(element) {
    // Copy the full visible text of the list item, including any nested options/sub-lists
    const textToCopy = (element.innerText || element.textContent || '').trim();
    if (!textToCopy) throw new Error('List item content is empty.');
    await this._copyToClipboard(textToCopy);
    this.showNotification('List content copied!');
}

Files Modified

  • js/client-modules/list-item-controller.js - Updated main copy logic
  • js/rendered-page-builder.js - Applied same fix to inlined controller for rendered pages

Testing

Tested with markdown content containing numbered questions with nested bullet point options (like math homework problems). The fix ensures that long-pressing a question copies both the question text and all its nested options.

Screenshot showing working long-press copy functionality

Backwards Compatibility

  • No public APIs changed
  • Feature flag ENABLE_LIST_LONG_PRESS_COPY and UI toggle remain unchanged
  • Existing highlight, notifications, and movement-cancel behavior preserved
  • Works in both normal and fallback render pipelines

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Sep 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
markdown Ready Ready Preview Comment Sep 7, 2025 1:57pm

@hihumanzone hihumanzone closed this Sep 7, 2025
@hihumanzone hihumanzone deleted the copilot/vscode1757253437851 branch September 7, 2025 14:00
Copilot AI restored the copilot/vscode1757253437851 branch September 7, 2025 14:01
Copilot AI changed the title [WIP] Fix long-press copy to include nested list options by copying visible list item text Fix long-press copy to include nested list options by copying visible list item text Sep 7, 2025
Copilot AI requested a review from hihumanzone September 7, 2025 14:06
@hihumanzone hihumanzone deleted the copilot/vscode1757253437851 branch September 8, 2025 08:09
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