Skip to content

Add selectAll to Sheet#6

Merged
hackerwins merged 1 commit into
mainfrom
select-all
Aug 3, 2024
Merged

Add selectAll to Sheet#6
hackerwins merged 1 commit into
mainfrom
select-all

Conversation

@hackerwins

@hackerwins hackerwins commented Aug 2, 2024

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it?

Add selectAll to Sheet

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced a keyboard shortcut for selecting all items in the worksheet using the 'a' key with meta/control keys.
    • Added new functions to enhance range operations, including checking collapsed ranges and merging ranges.
    • Enhanced the Sheet class with methods for checking range contents, retrieving active cell, and selecting all cells.
  • Bug Fixes

    • Improved handling of range selection and content checks to ensure accurate functionality.
  • Tests

    • Added new test cases for validating range functions and selection logic in the Sheet class.

@hackerwins
hackerwins marked this pull request as ready for review August 3, 2024 04:16
@hackerwins
hackerwins marked this pull request as draft August 3, 2024 04:19
@hackerwins
hackerwins marked this pull request as ready for review August 3, 2024 04:19
@coderabbitai

coderabbitai Bot commented Aug 3, 2024

Copy link
Copy Markdown

Walkthrough

The recent changes enhance the functionality of the worksheet and sheet components in the spreadsheet application. Key updates include the introduction of new keyboard shortcuts for selecting all items, improved range management methods, and a well-structured testing suite. These modifications collectively improve user interaction, provide additional range operations, and ensure robust testing of new features, resulting in a more efficient and user-friendly experience.

Changes

Files Change Summary
src/spreadsheet/worksheet.ts Added a keyboard shortcut for selecting all items with the 'a' key while holding meta/control keys.
src/worksheet/coordinates.ts Introduced range-related functions: isCollapsedRange, isSameRange, toBorderRanges, and mergeRanges.
src/worksheet/sheet.ts Added methods for range management: hasContents, getRangeOrActiveCell, and selectAll.
test/sheet/coordinates.test.ts Added tests for the toBorderRanges function to validate its behavior with various inputs.
test/sheet/sheet.test.ts Reorganized tests into specific blocks: 'Sheet.Data', 'Sheet.Selection', and 'Sheet.SelectAll' for clarity and modularity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Worksheet
    participant Sheet

    User->>Worksheet: Press 'a' + Meta/Control
    Worksheet->>Sheet: Call selectAll()
    Sheet->>Sheet: Check contents with hasContents()
    Sheet->>User: Select all items
Loading

🐇 "In a world of cells and sheets,
With 'a' and control, my joy repeats,
I bound through ranges, wide and free,
Selecting all with glee, oh me!
With new tests bright and functions grand,
My spreadsheet magic's at your hand!" 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
src/worksheet/coordinates.ts (1)

120-155: LGTM! Consider adding inline comments for clarity.

The toBorderRanges function correctly calculates and returns the border ranges. Adding inline comments would improve readability.

+  // Check if the top border is within the dimension
   if (range[0].r > dimension[0].r) {
     borders.push([
       { r: range[0].r - 1, c: range[0].c },
       { r: range[0].r - 1, c: range[1].c },
     ]);
   }

+  // Check if the bottom border is within the dimension
   if (range[1].r < dimension[1].r) {
     borders.push([
       { r: range[1].r + 1, c: range[0].c },
       { r: range[1].r + 1, c: range[1].c },
     ]);
   }

+  // Check if the left border is within the dimension
   if (range[0].c > dimension[0].c) {
     borders.push([
       { r: range[0].r, c: range[0].c - 1 },
       { r: range[1].r, c: range[0].c - 1 },
     ]);
   }

+  // Check if the right border is within the dimension
   if (range[1].c < dimension[1].c) {
     borders.push([
       { r: range[0].r, c: range[1].c + 1 },
       { r: range[1].r, c: range[1].c + 1 },
     ]);
   }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e684933 and 3b90daf.

Files selected for processing (5)
  • src/spreadsheet/worksheet.ts (1 hunks)
  • src/worksheet/coordinates.ts (2 hunks)
  • src/worksheet/sheet.ts (4 hunks)
  • test/sheet/coordinates.test.ts (2 hunks)
  • test/sheet/sheet.test.ts (3 hunks)
Additional comments not posted (14)
test/sheet/coordinates.test.ts (2)

57-87: LGTM! The test case is well-structured and covers the expected behavior.

The test case for toBorderRanges correctly validates the border ranges for the given range and dimension.


89-101: LGTM! The test case is well-structured and covers the edge case.

The test case for toBorderRanges correctly validates the exclusion of border ranges that fall outside the defined dimension.

test/sheet/sheet.test.ts (7)

Line range hint 4-15:
LGTM! The test case is well-structured and covers the basic functionality.

The test case for setting and getting data in the Sheet class correctly validates the expected behavior.


Line range hint 17-22:
LGTM! The test case is well-structured and covers the expected behavior.

The test case for updating the selection in the Sheet class correctly validates the expected behavior.


Line range hint 24-36:
LGTM! The test case is well-structured and covers the expected behavior.

The test case for moving the selection in the Sheet class correctly validates the expected behavior.


Line range hint 38-50:
LGTM! The test case is well-structured and covers the edge case.

The test case for not moving the selection beyond the sheet dimensions in the Sheet class correctly validates the expected behavior.


Line range hint 52-73:
LGTM! The test case is well-structured and covers the expected behavior.

The test case for moving the selection to the content edge in the Sheet class correctly validates the expected behavior.


76-89: LGTM! The test case is well-structured and covers the edge case.

The test case for the selectAll method correctly validates the behavior when the selection is outside the content range.


90-109: LGTM! The test case is well-structured and covers the edge case.

The test case for the selectAll method correctly validates the behavior when the selection is on the top left corner of the content range.

src/worksheet/coordinates.ts (3)

79-85: LGTM! The function is well-implemented and straightforward.

The isCollapsedRange function correctly checks if a given range is collapsed.


113-118: LGTM! The function is well-implemented and straightforward.

The isSameRange function correctly checks if two ranges are the same.


157-174: LGTM! The function is well-implemented and straightforward.

The mergeRanges function correctly merges two ranges into a single range.

src/worksheet/sheet.ts (1)

222-229: LGTM!

The getRangeOrActiveCell method is straightforward and correctly returns the current range or the active cell.

src/spreadsheet/worksheet.ts (1)

335-339: LGTM!

The new conditional check for the 'a' key with meta or control key to trigger the selectAll method is correctly integrated and enhances user interaction.

Comment thread src/worksheet/sheet.ts
Comment thread src/worksheet/sheet.ts
@hackerwins
hackerwins merged commit 810a3dc into main Aug 3, 2024
@hackerwins
hackerwins deleted the select-all branch August 3, 2024 04:25
hackerwins added a commit that referenced this pull request Apr 18, 2026
- Add Multer fileSize/fileFilter to FileInterceptor (#3)
- Move external input guard before all keyboard shortcuts (#5)
- Re-anchor image to cell under top-left after drag move (#6)
- Use drop coordinates for image insertion position (#7)
- Move file input outside desktop branch for mobile (#8)
- Gate context menu delete on onDeleteImage handler (#9)
hackerwins added a commit that referenced this pull request Apr 18, 2026
- Use pointerup coordinates for final draft commit (#6)
- Handle pointercancel to clear stuck drag state (#7)
- Preserve aspect ratio when clamping corner resizes (#4)
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.

1 participant