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 braille next line command for documents of Notepad++ #17431

Merged
merged 9 commits into from
Nov 27, 2024

Conversation

nvdaes
Copy link
Collaborator

@nvdaes nvdaes commented Nov 23, 2024

Link to issue number:

Fixes #17430

Summary of the issue:

Next braille line command doesn't work in Notepad++ documents when the last line is empty.

Description of user facing changes

Next braille line command works as expected in Notepad++ documents.

Description of development approach

The collapse method is overriden for Scintilla textInfo, so that textInfo is expanded to line before collapsing to end. In this way the cursor is properly moved to the end of the document when running the braille next line command.

Testing strategy:

Tested manually in portable Notepad++ on Windows 11.

Known issues with pull request:

None. Should be tested in different versions of Notepad++ and Windows.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

Summary by CodeRabbit

Release Notes for NVDA 2024.1

  • New Features

    • Support for the new HID Braille specification for automatic detection of multiple Braille displays.
    • Introduced "on-demand" speech mode, allowing users to control when speech is spoken.
    • Added "Native Selection" mode for Mozilla Firefox for improved text selection.
    • Add-on Store now alerts users of available updates at startup.
    • Support for Unicode normalization in speech and braille output.
  • Bug Fixes

    • Resolved cursor movement issues in Notepad++ documents with new text handling features.
  • Improvements

    • Enhanced performance and stability, especially in Microsoft Office applications.

@nvdaes nvdaes changed the title Fix collapse for textInfo in Notepad++ Fix braille next line command for documents of Notepad++ Nov 23, 2024
@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 24, 2024

I think that this is an API break change since the collapse method is changed in Scintilla TextInfo. So I'll document this in changes for developers.
I'll mark this as ready for review in case coderabbit can provide suggestions.
This bug was commented by @SaschaCowley in PR #17401

@AppVeyorBot
Copy link

  • PASS: Translation comments check.
  • PASS: License check.
  • PASS: Unit tests.
  • PASS: Lint check.
  • FAIL: System tests (tags: installer NVDA). See test results for more information.
  • Build (for testing PR): https://ci.appveyor.com/api/buildjobs/1gapuh75yd6b2ywv/artifacts/output/l10nUtil.exe nvda_snapshot_pr17431-34620,2591d8d3.exe
  • CI timing (mins):
    INIT 0.0,
    INSTALL_START 1.2,
    INSTALL_END 0.9,
    BUILD_START 0.0,
    BUILD_END 23.8,
    TESTSETUP_START 0.0,
    TESTSETUP_END 0.4,
    TEST_START 0.0,
    TEST_END 18.7,
    FINISH_END 0.2

See test results for failed build of commit 2591d8d3c0

@nvdaes nvdaes marked this pull request as ready for review November 24, 2024 17:25
@nvdaes nvdaes requested a review from a team as a code owner November 24, 2024 17:25
@nvdaes nvdaes requested a review from SaschaCowley November 24, 2024 17:25
@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 24, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

Walkthrough

The changes introduce a new method called collapse in the ScintillaTextInfo class within the scintilla.py file, which expands text information to the line level under specific conditions. Additionally, the documentation for NVDA 2024.1 highlights several new features, such as support for the new HID Braille specification, an "on-demand" speech mode, and a "Native Selection" mode for Firefox. These updates aim to enhance user experience and accessibility.

Changes

Files Change Summary
source/NVDAObjects/window/scintilla.py Added method collapse(self, end=False) to ScintillaTextInfo class to handle cursor movement in Notepad++.
user_docs/en/changes.md Documented new features for NVDA 2024.1, including HID Braille support, "on-demand" speech mode, and more.
src/calculator.py Added method coderabbit_add(x, y) and updated method signature for coderabbit_formula(x, y, z). Renamed variable old_global_var to new_global_var.

Assessment against linked issues

Objective Addressed Explanation
Fix cursor movement in Notepad++ (Issue #17430)

Possibly related PRs

Suggested labels

conceptApproved, blocked/needs-testing

Suggested reviewers

  • LeonarddeR

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 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.

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
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

🧹 Outside diff range and nitpick comments (3)
source/NVDAObjects/window/scintilla.py (2)

316-321: Document this change in NVDA's developer documentation.

Since this overrides the collapse method behavior, it should be documented in the developer changes for NVDA 2024.1 to inform other developers about this change in the Scintilla text info API.


322-324: Consider adding unit tests for the collapse method.

To ensure the behavior remains correct across future changes, consider adding unit tests covering:

  1. Collapsing to end with no selection
  2. Collapsing to end with selection
  3. Collapsing to start

Would you like me to help generate the unit test code?

user_docs/en/changes.md (1)

119-119: Improve technical documentation clarity

The developer change description could be clearer and more structured.

-* in `NVDAObjects.window.scintilla.ScintillaTextInfo`, if no text is selected, the `collapse` method is overriden to expand to line if the `end` parameter is set to `True` (#17431, @nvdaes)
+* In `NVDAObjects.window.scintilla.ScintillaTextInfo`, the `collapse` method is overridden.
+  When no text is selected and the `end` parameter is `True`, the method expands to line before collapsing.
+  (#17431, @nvdaes)
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c32e0e7 and cdcd270.

📒 Files selected for processing (2)
  • source/NVDAObjects/window/scintilla.py (1 hunks)
  • user_docs/en/changes.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
source/NVDAObjects/window/scintilla.py (2)

Pattern **/*: Focus on code smells, logic errors, edge cases, missing test cases, security flaws and serious issues. Avoid commenting on minor issues such as linting, formatting and style issues. This project uses tabs instead of spaces, do not suggest usage of spaces over tabs. Are there any 'red flags' in this code that might warrant closer investigation from a security standpoint? Explain what makes them suspicious. When providing code suggestions, particularly when requested, ensure GitHub's suggestion format is used, i.e.: suggestion <code changes>


Pattern **/*.py: _, pgettext, ngettext, and ngettext are defined globally, errors for this being undefined can be ignored.

user_docs/en/changes.md (3)

Pattern **/*: Focus on code smells, logic errors, edge cases, missing test cases, security flaws and serious issues. Avoid commenting on minor issues such as linting, formatting and style issues. This project uses tabs instead of spaces, do not suggest usage of spaces over tabs. Are there any 'red flags' in this code that might warrant closer investigation from a security standpoint? Explain what makes them suspicious. When providing code suggestions, particularly when requested, ensure GitHub's suggestion format is used, i.e.: suggestion <code changes>


Pattern **/*.md: Focus on grammar, spelling, and punctuation. Also consider readability and clarity of contents. Ensure that changes follow the style of one sentence per line, suggest changes if this is not met.


Pattern user_docs/en/changes.md: Ensure each change log entry references an issue or pull request number. Change log entries can also include a reference to a GitHub author. Examples of valid change log entries: * Item with sub-items (#123, @username): * sub-item * bar (#342) * Item with. Multiple lines. (#143)

🔇 Additional comments (1)
source/NVDAObjects/window/scintilla.py (1)

316-324: LGTM! Well-documented fix for the braille next line command.

The implementation correctly addresses the issue by expanding to line level before collapsing to end, when no text is selected. The code is clean and the documentation clearly explains the purpose and links to the issue.

Let's verify this change doesn't affect other Scintilla-based editors:

✅ Verification successful

The change is safe and properly scoped to Scintilla-based editors

The verification shows that Notepad++ is the only editor implementation that inherits from ScintillaBase, and it uses the same text information base class. The collapse behavior modification will be consistently applied across all Scintilla instances, maintaining uniform behavior for braille navigation.

  • The change affects ScintillaTextInfo which is the base class used by Notepad++ through ScintillaTextInfoNpp83
  • No other editor implementations were found that could be impacted differently
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other Scintilla-based editor implementations
rg -l "class.*\(.*Scintilla.*\)" source/

Length of output: 79


Script:

#!/bin/bash
# Let's check the content of notepadPlusPlus.py to understand how it uses Scintilla
rg -A 5 "class.*\(.*Scintilla.*\)" source/appModules/notepadPlusPlus.py

# Also check for any other references to Scintilla in the codebase
rg "Scintilla" source/ -l

Length of output: 815


Script:

#!/bin/bash
# Let's check the inheritance hierarchy to understand the base implementation
rg -A 10 "class ScintillaBase" source/NVDAObjects/window/scintilla.py

# Also check if there are any other editor implementations that might be affected
rg "class.*\(.*ScintillaBase" source/ --type py

Length of output: 298

user_docs/en/changes.md Outdated Show resolved Hide resolved
nvdaes and others added 3 commits November 24, 2024 18:37
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 24, 2024

@coderabbitai review

@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 24, 2024

@coderabbitai, please suggest unit tests for this PR.

Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

Tip

For best results, initiate chat on the files or code changes.

@nvdaes,

I've prepared some unit tests for the modified collapse method in ScintillaTextInfo. Since there were no existing unit tests for ScintillaTextInfo, I've created a new test class to verify the new behavior.

import unittest
from unittest.mock import patch
from source.NVDAObjects.window.scintilla import ScintillaTextInfo
import textInfos

class MockScintillaObject:
    """Mock object to simulate Scintilla NVDAObject."""
    def __init__(self, selection_is_collapsed=True):
        self.selection_is_collapsed = selection_is_collapsed
        self.windowHandle = None  # Substitute with appropriate value if needed

    def makeTextInfo(self, position):
        class MockTextInfo:
            @property
            def isCollapsed(self):
                return self._is_collapsed

            @isCollapsed.setter
            def isCollapsed(self, value):
                self._is_collapsed = value

        text_info = MockTextInfo()
        text_info.isCollapsed = self.selection_is_collapsed
        return text_info

class TestScintillaTextInfoCollapse(unittest.TestCase):
    def setUp(self):
        self.mock_obj = MockScintillaObject(selection_is_collapsed=True)
        self.text_info = ScintillaTextInfo(self.mock_obj)

    def test_collapse_end_with_collapsed_selection_expands_line(self):
        with patch.object(self.text_info, 'expand') as mock_expand, \
             patch('textInfos.offsets.OffsetsTextInfo.collapse') as mock_super_collapse:
            self.text_info.collapse(end=True)
            mock_expand.assert_called_once_with(textInfos.UNIT_LINE)
            mock_super_collapse.assert_called_once_with(end=True)

    def test_collapse_end_with_non_collapsed_selection_does_not_expand(self):
        self.mock_obj.selection_is_collapsed = False
        with patch.object(self.text_info, 'expand') as mock_expand, \
             patch('textInfos.offsets.OffsetsTextInfo.collapse') as mock_super_collapse:
            self.text_info.collapse(end=True)
            mock_expand.assert_not_called()
            mock_super_collapse.assert_called_once_with(end=True)

    def test_collapse_not_end_does_not_expand(self):
        with patch.object(self.text_info, 'expand') as mock_expand, \
             patch('textInfos.offsets.OffsetsTextInfo.collapse') as mock_super_collapse:
            self.text_info.collapse(end=False)
            mock_expand.assert_not_called()
            mock_super_collapse.assert_called_once_with(end=False)

if __name__ == '__main__':
    unittest.main()

Explanation:

  • Test Case 1: Verifies that when end=True and the selection is collapsed, the expand method is called with textInfos.UNIT_LINE, and then collapse proceeds.
  • Test Case 2: Checks that if the selection is not collapsed, expand is not called even when end=True.
  • Test Case 3: Ensures that when end=False, expand is not called regardless of the selection state.

Notes:

  • I've used unittest.mock.patch to mock the expand method and the superclass's collapse method to verify that they are called as expected.
  • The MockScintillaObject simulates the necessary parts of the Scintilla object, particularly the makeTextInfo method and the selection_is_collapsed property.
  • Adjust the windowHandle and other attributes in MockScintillaObject as needed to fit the actual implementation.

Let me know if you need any further assistance or adjustments to these tests.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Display the contents of 'source/NVDAObjects/window/scintilla.py'
cat source/NVDAObjects/window/scintilla.py

# Find existing unit test files that mention 'ScintillaTextInfo'
fd --type f --name 'test_*.py' | xargs grep -l 'ScintillaTextInfo'

# Display the contents of the identified test files
fd --type f --name 'test_*.py' | xargs grep -l 'ScintillaTextInfo' | xargs cat

Length of output: 12366


Script:

#!/bin/bash
# Corrected the fd command usage.

# Display the contents of 'source/NVDAObjects/window/scintilla.py'
cat source/NVDAObjects/window/scintilla.py

# Find existing unit test files that mention 'ScintillaTextInfo'
fd --glob 'test_*.py' --type f | xargs grep -l 'ScintillaTextInfo'

# Display the contents of the identified test files
fd --glob 'test_*.py' --type f | xargs grep -l 'ScintillaTextInfo' | xargs cat

Length of output: 11864

@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 24, 2024

Since ScintillaTextInfo doesn't have unit tests, I'll wait for developers comments about this.

source/NVDAObjects/window/scintilla.py Outdated Show resolved Hide resolved
user_docs/en/changes.md Outdated Show resolved Hide resolved
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Nov 26, 2024
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
@nvdaes
Copy link
Collaborator Author

nvdaes commented Nov 26, 2024

Thanks for your review, @seanbudd . I've applied your suggestions.

@seanbudd seanbudd merged commit 70cd311 into nvaccess:master Nov 27, 2024
5 checks passed
@github-actions github-actions bot added this to the 2025.1 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notepad++: braille doesn't move to the next line if last line is empty
3 participants