Skip to content
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

Fix ItemToggle Duplicate Item When Refreshing Menu in Callback #286

Merged
merged 7 commits into from
Jan 4, 2025

Conversation

mriveralee
Copy link
Contributor

@mriveralee mriveralee commented Jan 4, 2025

Description

This PR fixes #264. I reproduced this bug and have found the issue: ItemToggle::toggle() executes its callback function before it redraws. When menu.refresh() is in the callback function, it changes the cursor row position to the max row. Then ItemToggle calls its draw to duplicate the item on the last visible row.

The simple solution here is to move the callback after the redraw. A similar approach is used in ItemInput, ItemInput::back()(https://github.com/forntoh/LcdMenu/blob/master/src/ItemInput.h#L189) , which calls draw(...) first and then execute the callback.

How Has This Been Tested?

I used the provided code in #264 with an Arduino Nano, LCD Display 4x20 I2C , and Rotary Encoder. I tested by running the code, toggle the first item to trigger the menu.refresh() call, and visually verified the problem is resolved. I also tested the individual toggle examples to make sure the behavior works as expected.

Additional Notes


Checklist

General Requirements

  • I have kept this PR in draft until all the required tasks are completed.
  • I have reviewed the contributing guidelines for this project.
  • I have tagged this PR with breaking-change if it introduces a breaking change.
  • I have checked that this PR does not introduce any breaking changes unless explicitly stated.
  • I have checked that changes generate no new warnings.
  • I have performed a self-review of my own code
  • I have built and tested ALL the examples to ensure that I haven't broken anything.

Bug Fix

  • This PR is a bug fix.
  • I have tagged this PR with bugfix.
  • I have added a link to the bug in the description.
  • I have added tests that prove my fix is effective.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved toggle state management to ensure logging and drawing operations accurately reflect the updated item state after toggling.
  • Chores

    • Updated GitHub Actions workflow for lint checking to disable automatic fixes and commits during the linting process.

Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

The changes in the ItemToggle.h file involve repositioning the logging and drawing operations to occur after the state change of the enabled variable in the toggle method. This modification ensures that the logging and drawing accurately reflect the updated state of the toggle item, maintaining the existing control flow and callback mechanism. Additionally, the GitHub Actions workflow for lint checking has been updated to disable automatic fixing and committing of changes.

Changes

File Change Summary
src/ItemToggle.h Reordered logging and drawing operations to execute after state change in toggle method
.github/workflows/lint_check.yml Updated linting action parameters: disabled auto_fix and commit options

Assessment against linked issues

Objective Addressed Explanation
Resolve duplicated last activated item after refresh (#264) Unable to definitively confirm if this change fully resolves the issue without seeing the complete implementation.

Poem

🐰 A toggle's dance, a state's new stance,
Logging moves, with graceful prance.
After change, the truth is clear,
No more duplicates to fear!
Code hops forward, bright and light 🌟


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>, 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. (Beta)
  • @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.

@mriveralee mriveralee changed the title bugfix Fix ItemToggle Duplicate Item When Refreshing Menu in Callback bugfix Fix ItemToggle Duplicate Item When Refreshing Menu in Callback; fixes #264 Jan 4, 2025
@mriveralee mriveralee changed the title bugfix Fix ItemToggle Duplicate Item When Refreshing Menu in Callback; fixes #264 bugfix Fix ItemToggle Duplicate Item When Refreshing Menu in Callback Jan 4, 2025
Copy link
Contributor

@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: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9c94bc and 4291de0.

📒 Files selected for processing (2)
  • src/ItemToggle.h (1 hunks)
  • src/LcdMenu.cpp (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/ItemToggle.h (1)
Learnt from: forntoh
PR: forntoh/LcdMenu#250
File: src/ItemToggle.h:105-105
Timestamp: 2024-11-12T11:59:37.512Z
Learning: In the file `src/ItemToggle.h`, the logging format `"ItemToggle::toggle"` used in the `toggle` method matches the convention used in other files.
🔇 Additional comments (1)
src/ItemToggle.h (1)

102-103: Ordering looks correct.

Toggling the enabled state before logging and calling draw() ensures the displayed state matches the internal state. Invoking the callback last prevents any race conditions during UI updates. This is coherent with the fix described in the PR. Good job!

src/LcdMenu.cpp Outdated Show resolved Hide resolved
@mriveralee mriveralee force-pushed the fixDisplayRefreshDupe branch from 4291de0 to 1835741 Compare January 4, 2025 03:13
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 4, 2025
@mriveralee mriveralee marked this pull request as ready for review January 4, 2025 03:46
@mriveralee mriveralee requested a review from forntoh as a code owner January 4, 2025 03:46
@forntoh forntoh added the bugfix I have fixed a bug label Jan 4, 2025
@forntoh forntoh changed the title bugfix Fix ItemToggle Duplicate Item When Refreshing Menu in Callback Fix ItemToggle Duplicate Item When Refreshing Menu in Callback Jan 4, 2025
- Disabled auto-fix and commit options in lint check.
- Added dynamic repository reference in CI setup.
- Disabled auto-fix and commit options in lint check.
- Added dynamic repository reference in CI setup.
@forntoh forntoh dismissed coderabbitai[bot]’s stale review January 4, 2025 10:51

The merge-base changed after approval.

Copy link
Contributor

@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: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1835741 and 0155cea.

📒 Files selected for processing (1)
  • .github/workflows/lint_check.yml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: forntoh
PR: forntoh/LcdMenu#250
File: src/ItemToggle.h:105-105
Timestamp: 2024-11-12T11:59:37.512Z
Learning: In the file `src/ItemToggle.h`, the logging format `"ItemToggle::toggle"` used in the `toggle` method matches the convention used in other files.

.github/workflows/lint_check.yml Show resolved Hide resolved
@forntoh forntoh merged commit 40b3a1b into forntoh:master Jan 4, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix I have fixed a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Duplicated last activated item after manual refresh
2 participants