Skip to content

feat(editor): Add "Copy Log Event" option to context menu (resolves #179). #197

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

Merged
merged 21 commits into from
Mar 5, 2025

Conversation

hoophalab
Copy link
Contributor

@hoophalab hoophalab commented Mar 4, 2025

fixes #179).

Description

Add a context menu item to allow users to easily select and copy a single log event when it spans multiple lines.

copy-log-event

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Right-clicking on any line in the editor and selecting the "Copy log event" item selects the entire log event and copys it to the clipboard.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a new editor action that allows users to copy log events directly using a dedicated keyboard shortcut.
    • Enhanced the editor's interaction by enabling selection of log event details when hovering over them.
    • Improved the organization of custom actions in the editor's context menu, making features more intuitive to use.
    • Added support for context menu grouping and ordering for custom actions in the editor.
    • Expanded the flexibility of action properties for custom actions in the editor.

@hoophalab hoophalab requested a review from a team as a code owner March 4, 2025 15:06
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

The update enhances the Monaco editor's custom action setup and introduces a feature for copying log events. The setupCustomActions function has been modified to accept additional properties, allowing for greater flexibility in action descriptors. New functions in the Editor component facilitate the retrieval of selected log events and implement a copy action. An enum value and a corresponding action definition for copying log events have also been added to support this functionality.

Changes

File(s) Change Summary
src/components/Editor/MonacoInstance/actions.ts Updated setupCustomActions to destructure additional properties from the actions array, enhancing flexibility in action descriptors.
src/components/Editor/index.tsx Introduced getSelectedLogEventNum and handleCopyLogEventAction for managing log event copying; modified handleEditorCustomAction to handle ACTION_NAME.COPY_LOG_EVENT.
src/utils/actions.ts Added COPY_LOG_EVENT to the ACTION_NAME enum; updated EditorAction to include optional properties contextMenuGroupId and contextMenuOrder; created a new action object for copying log events with relevant properties.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant E as Editor
    participant D as Document

    U->>E: Select a log event line
    E->>E: Execute getSelectedLogEventNum()
    E->>U: Return log event number (or null)
    U->>E: Trigger COPY_LOG_EVENT action via context menu
    E->>E: Call handleCopyLogEventAction()
    E->>E: Set selection range on log event line(s)
    E->>D: Execute document.execCommand("copy")
    D-->>E: Confirm text copied to clipboard
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Editor/index.tsx (2)

72-120: Consider using the modern Clipboard API instead of the deprecated execCommand.

While the current implementation works, document.execCommand("copy") is deprecated. Consider using the Clipboard API for better future compatibility:

-    // Monaco editor uses `document.execCommand` instead of the Clipboard API to copy text.
-    // eslint-disable-next-line @typescript-eslint/no-deprecated
-    editor.getContainerDomNode().ownerDocument.execCommand("copy");
+    // Get the selected text from the editor
+    const selectedText = editor.getModel()?.getValueInRange(editor.getSelection());
+    
+    // Use the Clipboard API with fallback to execCommand
+    if (selectedText && navigator.clipboard) {
+        navigator.clipboard.writeText(selectedText).catch(() => {
+            // Fallback if clipboard API fails
+            // eslint-disable-next-line @typescript-eslint/no-deprecated
+            editor.getContainerDomNode().ownerDocument.execCommand("copy");
+        });
+    } else {
+        // Fallback for browsers without Clipboard API
+        // eslint-disable-next-line @typescript-eslint/no-deprecated
+        editor.getContainerDomNode().ownerDocument.execCommand("copy");
+    }

Also, consider adding user feedback (like a toast notification) to indicate successful copying.


108-113: Ensure endLineNumber is always valid.

There's a potential edge case where maxLineNum - 1 could result in a negative number if the document is empty (though unlikely). Consider adding a safeguard:

const maxLineNum: number = model.getLineCount();
const startLineNumber: number = hoveredLogEventLineNum;
const endLineNumber: number = null === nextLogEventLineNum ?
-    maxLineNum - 1 :
+    Math.max(maxLineNum - 1, startLineNumber) :
    nextLogEventLineNum - 1;

This ensures that even in edge cases, endLineNumber is always at least equal to startLineNumber.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8455e and c8f5222.

📒 Files selected for processing (3)
  • src/components/Editor/MonacoInstance/actions.ts (1 hunks)
  • src/components/Editor/index.tsx (2 hunks)
  • src/utils/actions.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/utils/actions.ts
  • src/components/Editor/MonacoInstance/actions.ts
  • src/components/Editor/index.tsx
🔇 Additional comments (8)
src/utils/actions.ts (3)

15-15: Good addition of a new action to copy log events.

The enum name is clear and follows the existing convention for naming actions.


22-22: Good enhancement to the EditorAction interface.

The optional contextMenuGroupId property allows for better organization of context menu items.


65-70: Well-defined new action for copying log events.

The action is properly configured with:

  • Descriptive label that clearly communicates the purpose
  • Appropriate key bindings (Ctrl/Cmd+Shift+C)
  • Context menu grouping that helps organize the right-click menu

This implementation aligns well with the PR objective of adding a menu item to copy a single log event.

src/components/Editor/MonacoInstance/actions.ts (3)

158-158: Good update to destructure the new contextMenuGroupId property.

The function signature update maintains backward compatibility since the property is optional.


162-169: Good refactoring to use a descriptor object.

Creating a separate descriptor object improves code readability compared to passing an inline object to editor.addAction.


171-174: Proper conditional handling of the contextMenuGroupId property.

The type check using "undefined" !== typeof contextMenuGroupId follows the coding guidelines preference for explicit comparison rather than using the negation operator.

src/components/Editor/index.tsx (2)

42-70: Well-implemented helper function to identify hovered log events.

The function is well-documented with JSDoc comments and includes proper null/undefined checks. It correctly uses the utility function to find the corresponding log event number based on line position.


163-167: Good implementation of the COPY_LOG_EVENT action handler.

The case properly calls the new handler function with the required parameters and follows the pattern of existing action handlers.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

lgtm at a high level

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8f5222 and d747c63.

📒 Files selected for processing (3)
  • src/components/Editor/MonacoInstance/actions.ts (1 hunks)
  • src/components/Editor/index.tsx (2 hunks)
  • src/utils/actions.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Editor/index.tsx
  • src/components/Editor/MonacoInstance/actions.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/utils/actions.ts
🔇 Additional comments (3)
src/utils/actions.ts (3)

15-15: LGTM! Well-integrated enum addition for the new copy log event action.

The new COPY_LOG_EVENT enum value is clearly named and follows the same pattern as existing enum values.


20-21: LGTM! Type definitions properly implemented.

The new interface properties use the Nullable<string> and Nullable<number> types correctly, which is preferable to using the optional property syntax with ? as it makes the intent clearer.


66-72: LGTM! Well-configured action for copying log events.

The new action is well-structured and includes appropriate keyboard shortcuts for the copy log event action. Using contextMenuGroupId: "9_cutcopypaste" puts this action in the same group as other copy/paste actions, which is good for discoverability.

As discussed in a previous review, putting the "Copy Log Event" button in the same group as the standard "Copy" button (using "9_cutcopypaste") makes sense from a user experience perspective.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Editor/index.tsx (2)

72-121: Good implementation with a minor consideration for modern clipboard API.

The implementation correctly handles copying the selected log event to the clipboard, including proper edge case handling. It calculates the start and end of the log event properly, sets the selection in the editor, and then initiates the copy operation.

While the code uses the deprecated document.execCommand("copy") API (with a proper comment explaining why), consider evaluating if the Clipboard API could be used as a more modern alternative in a future update:

// Future consideration (not required for this PR)
navigator.clipboard.writeText(model.getValueInRange({
  startLineNumber: startLineNumber,
  startColumn: 1,
  endLineNumber: endLineNumber,
  endColumn: endMaxColumn
}));

This is just a suggestion for future improvements, as noted in previous review comments where it was discussed and decided to stick with the current approach.


104-113: Consider simplifying line range calculation using Math.min.

The logic for calculating the end line number is correct, but could be simplified.

-    const endLineNumberMaybeNegative: number = null === nextLogEventLineNum ?
-        maxLineNum - 1 :
-        nextLogEventLineNum - 1;
-    const endLineNumber: number = Math.max(startLineNumber, endLineNumberMaybeNegative);
+    const endLineNumber: number = null === nextLogEventLineNum ? 
+        maxLineNum :
+        Math.max(startLineNumber, nextLogEventLineNum - 1);

This change reduces the need for the variable endLineNumberMaybeNegative and makes the intention clearer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d747c63 and d041f85.

📒 Files selected for processing (1)
  • src/components/Editor/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/Editor/index.tsx
🔇 Additional comments (3)
src/components/Editor/index.tsx (3)

42-70: Function name should be more descriptive of its action.

The function name getSelectedLogEventNum is somewhat misleading as it retrieves the log event number from a mouse position in the editor, rather than from an actual selection. Based on the previous review comments, there was a discussion about naming this function, and getSelectedLogEventNum was agreed upon instead of getHoveredLogEventNum.

The implementation itself is good and follows the proper coding guidelines with the false == pattern on line 54 rather than using the negation operator.


164-168: Action handler integrated properly.

The handler for the new COPY_LOG_EVENT action is correctly implemented. It retrieves the current mapping from the ref and calls the appropriate function.


42-121: Verify multi-event selection handling.

As discussed in previous review comments, handling the case where a user has selected multiple lines across different log events when clicking the "Copy Log Event" button is planned for a future PR. This current implementation only copies a single log event regardless of the existing selection.

This is acceptable for the current PR as agreed upon, but should be tracked for future enhancement.

@hoophalab hoophalab requested a review from junhaoliao March 4, 2025 19:24
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

some final suggestions

@junhaoliao
Copy link
Member

For the PR title, how about

feat(editor): Add "Copy Log Event" option to context menu (resolves #179).

@hoophalab hoophalab changed the title feat: Add a menu item to copy a single log event into the clipboard (fixes #179). feat(editor): Add "Copy Log Event" option to context menu (resolves #179). Mar 5, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/utils/actions.ts (1)

19-23: ⚠️ Potential issue

Add default values to existing EditorAction objects

The interface now requires new properties contextMenuGroupId and contextMenuOrder, but the existing action objects in EDITOR_ACTIONS don't specify these properties. This mismatch could cause TypeScript to generate errors.

Apply this change to all existing action objects in the array:

    {
        actionName: null,
        label: "Focus on Editor",
        keyBindings: [monaco.KeyCode.Backquote],
+       contextMenuGroupId: null,
+       contextMenuOrder: null,
    },

This should be done for all existing action objects (lines 31-65).

🧹 Nitpick comments (2)
src/components/Editor/index.tsx (2)

42-70: Function to retrieve log event number is well-implemented

The function correctly retrieves the log event number based on the currently selected line in the editor. Error handling is appropriate for cases where no selection exists or when the mapping is unavailable.

However, for better naming consistency, consider renaming the parameter:

const getSelectedLogEventNum = (
    editor: monaco.editor.IStandaloneCodeEditor,
-   beginLineNumToLogEventNumRefCurrent: BeginLineNumToLogEventNumMap
+   beginLineNumToLogEventNum: BeginLineNumToLogEventNumMap
): Nullable<number> => {

This would align with the parameter naming in other functions and make the code more readable.


90-98: Improve null handling for better error reporting

The "unreachable" comment suggests that this case shouldn't happen, but robust code should still handle potential errors explicitly rather than silently returning.

    if (null === selectedLogEventLineNum) {
-        // unreachable
-        return;
+        throw new Error("Selected log event line number is null despite having a valid log event number.");
    }

This would provide better diagnostics if this "unreachable" code is ever reached in practice.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d041f85 and 1ce2cd7.

📒 Files selected for processing (2)
  • src/components/Editor/index.tsx (2 hunks)
  • src/utils/actions.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/utils/actions.ts
  • src/components/Editor/index.tsx
🔇 Additional comments (3)
src/utils/actions.ts (2)

15-15: New enum value added for log event copying

This addition to the enum is well-defined and follows the naming convention established in the rest of the enum.


66-72: Copy Log Event action defined with appropriate parameters

The new action for copying log events is well-defined with all necessary properties. The action is assigned to the "9_cutcopypaste" context menu group with order 2, which should place it appropriately in the context menu next to other copy/paste operations.

src/components/Editor/index.tsx (1)

164-166: Action handler implementation correctly dispatches to copy function

The implementation of the COPY_LOG_EVENT case in the switch statement is correct and follows the pattern established for other actions.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

posted another suggestion for simplifying setupCustomActions while keeping the contextMenuGroupId and contextMenuOrder optional (?) rather than Nullable.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/Editor/index.tsx (1)

64-112: Enhance error handling for the next log event line number

The current implementation has thorough error handling for selectedLogEventLineNum but doesn't explicitly check if nextLogEventLineNum is null before using it in the conditional branch that assumes it exists.

Consider implementing a more consistent error handling approach:

    if (null === selectedLogEventLineNum) {
        throw new Error("Unable to get the beginning line number of the selected log event.");
    }

    let endLineNumber: number;
    if (null !== nextLogEventLineNum) {
        endLineNumber = nextLogEventLineNum - 1;
    } else {
+       // Handle the case when this is the last log event in the file
        const model = editor.getModel();
        if (null === model) {
            throw new Error("Unable to get the text model.");
        }
        endLineNumber = model.getLineCount() - 1;
    }

The added comment helps clarify the else branch's purpose for future maintainers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce2cd7 and a92d937.

📒 Files selected for processing (3)
  • src/components/Editor/MonacoInstance/actions.ts (1 hunks)
  • src/components/Editor/index.tsx (2 hunks)
  • src/utils/actions.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Editor/MonacoInstance/actions.ts
  • src/utils/actions.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/Editor/index.tsx
🔇 Additional comments (3)
src/components/Editor/index.tsx (3)

42-62: Good implementation of selected log event detection!

The function is well-documented with clear JSDoc comments and properly handles the case when no line is selected. The implementation correctly uses the getMapValueWithNearestLessThanOrEqualKey utility function to find the corresponding log event number.


103-111: Good use of Monaco's built-in clipboard action!

The implementation correctly uses Monaco's built-in clipboard action instead of the deprecated document.execCommand API. Setting the selection and then triggering the copy action makes the operation more intuitive for users, as they can see what's being copied.


155-157: Proper integration of the copy action in the editor's action handler

The new case for handling the copy log event action is correctly implemented and properly integrated with the existing action handler.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Editor/index.tsx (2)

64-90: Consider consolidating error handling for both null checks

The function properly throws an error when selectedLogEventLineNum is null, but handles the nextLogEventLineNum being null differently. Consider using similar error handling approaches for both cases for greater consistency.

if (null === selectedLogEventLineNum) {
    throw new Error("Unable to get the beginning line number of the selected log event.");
}

The throw error approach is good for catching programming issues, but consider enhancing the error message to be more actionable, particularly for debugging purposes.


92-94: Prefer Yoda conditions for boolean comparisons

According to the coding guidelines, prefer false == <expression> rather than !<expression>. For consistency, you should also apply this pattern to null checks.

-if (null !== nextLogEventLineNum) {
+if (null === nextLogEventLineNum) {
+    // Handle the case when this is the last log event in the file.
+    const model = editor.getModel();
+    if (null === model) {
+        throw new Error("Unable to get the text model.");
+    }
+    endLineNumber = model.getLineCount() - 1;
+} else {
     endLineNumber = nextLogEventLineNum - 1;
-} else {
-    // Handle the case when this is the last log event in the file.
-    const model = editor.getModel();
-    if (null === model) {
-        throw new Error("Unable to get the text model.");
-    }
-    endLineNumber = model.getLineCount() - 1;
}

This maintains the Yoda condition style while keeping the same logic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a92d937 and 20739b8.

📒 Files selected for processing (1)
  • src/components/Editor/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/Editor/index.tsx
🔇 Additional comments (4)
src/components/Editor/index.tsx (4)

42-62: Function is well-implemented and follows naming recommendations

The implementation of getSelectedLogEventNum is clean and follows the naming convention agreed upon in previous discussions. It properly handles undefined line numbers and uses appropriate utility functions to find the log event number.


91-102: Good handling of the last log event edge case

The code properly handles the case when processing the last log event in the file by retrieving the model's line count. This is a good edge case consideration.


104-113: Excellent use of Monaco's clipboard API

The implementation uses Monaco's recommended clipboard action rather than deprecated methods, which is a best practice. Using Infinity for the column position is also a good approach to ensure selection to the end of each line.


156-158: Action handler is correctly integrated

The new case for ACTION_NAME.COPY_LOG_EVENT is properly integrated into the existing switch statement and correctly passes required parameters to the handler function.

@hoophalab hoophalab requested a review from junhaoliao March 5, 2025 19:53
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/Editor/index.tsx (1)

64-90: Consider adding error handling for the case when nextLogEventLineNum is null

Currently, you check if selectedLogEventLineNum is null and throw an error, but there's no explicit check for nextLogEventLineNum being null before it's used in the next section. Even though this might be addressed by the null check in the if-statement on line 93, it would be more explicit to validate both values at the same time.

if (null === selectedLogEventLineNum) {
    throw new Error("Unable to get the beginning line number of the selected log event.");
}
+
+if (null === nextLogEventLineNum && null === selectedLogEventLineNum + 1) {
+    // This is expected when handling the last log event
+    console.debug("This is the last log event in the file.");
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20739b8 and 01aeb3d.

📒 Files selected for processing (1)
  • src/components/Editor/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/Editor/index.tsx
🔇 Additional comments (3)
src/components/Editor/index.tsx (3)

42-62: Clear and well-implemented function for retrieving selected log event number

The function logic is clear, handles edge cases correctly, and returns the appropriate log event number based on the cursor position. The function documentation is comprehensive and accurate.


91-113: Good handling of the last log event case and use of Monaco editor's built-in clipboard action

This section:

  1. Properly handles the edge case when copying the last log event
  2. Correctly sets the selection range
  3. Uses Monaco's built-in clipboard action instead of deprecated APIs

The Infinity value for the end column ensures the entire line is selected, which is a neat solution.


156-158: Implementation follows the established pattern for editor custom actions

The new action handler is concise and follows the same pattern as other action handlers, using the current reference to beginLineNumToLogEventNum.

@hoophalab hoophalab merged commit 0418be7 into y-scope:main Mar 5, 2025
3 checks passed
@hoophalab hoophalab deleted the copy-log branch March 5, 2025 23:21
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.

Shortcut to copy a single log event into clipboard
2 participants