Skip to content

Conversation

@dengzhongyuan365-dev
Copy link
Contributor

@dengzhongyuan365-dev dengzhongyuan365-dev commented Sep 19, 2025

…nagement

  • Refactored the text input handling in the NameTextEdit class to improve cursor positioning and character limit enforcement.
  • Introduced a new method setMaxLength to dynamically set the maximum length for text input based on file suffixes.
  • Updated the renameFile method to reserve space for file suffixes, ensuring that the main file name is editable without truncating the suffix.

These changes enhance user experience by providing better control over text input and ensuring that file names are handled correctly.

bug: https://pms.uniontech.com/bug-view-321657.html

Summary by Sourcery

Enhance NameTextEdit to support dynamic maximum lengths, improve cursor positioning and trimming logic, and update renameFile to reserve suffix space and select only the base name for editing

New Features:

  • Add setMaxLength method to NameTextEdit for dynamic input length control

Bug Fixes:

  • Prevent file suffix truncation by reserving suffix space during file renaming

Enhancements:

  • Refactor NameTextEdit::slotTextChanged to simplify cursor management and apply dynamic max length

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

我对这段代码进行了审查,以下是我的分析和改进建议:

1. 代码逻辑改进

  1. 文本处理逻辑优化

    • 原代码在处理文本长度时直接使用 chop() 方法截断,可能导致文件名不完整。新代码改进为使用 FileUtils::processLength() 进行更精细的长度控制,优先保留文件后缀。
    • 添加了对后缀名的特殊处理逻辑,确保重命名时不会意外修改文件后缀。
  2. 光标位置处理改进

    • 原代码在计算光标位置时可能不够准确,新代码改进了光标位置的计算逻辑,确保编辑体验更流畅。

2. 代码质量提升

  1. 代码可读性

    • 添加了清晰的注释,解释了关键步骤的目的,特别是关于后缀名保留的逻辑。
    • 将复杂的文本处理逻辑分解为更小的步骤,提高了代码的可维护性。
  2. 代码结构优化

    • 新增了 setMaxLength() 方法,使长度限制的管理更加集中和灵活。
    • 将最大长度限制的逻辑从硬编码改为可配置的,提高了代码的复用性。

3. 性能优化

  1. 减少不必要的计算

    • 避免在每次文本变化时都进行完整的长度检查,只在必要时才进行长度限制处理。
    • 优化了字符串操作,减少了不必要的中间字符串创建。
  2. 光标操作优化

    • 改进了光标位置的计算方式,减少了不必要的光标移动操作。

4. 安全性增强

  1. 输入验证

    • 保留了非法字符过滤逻辑,确保文件名不包含不允许的字符。
    • 使用 qMax(0, len) 确保传入的长度值不会为负数。
  2. 边界条件处理

    • 增加了对空后缀名的处理逻辑,避免潜在的空指针访问。
    • 在设置光标位置时使用 qMin() 确保不会超出字符串范围。

5. 具体改进建议

  1. 常量定义

    • 建议将 NAME_MAX 定义为类常量或枚举值,而不是直接使用魔法数字。
  2. 错误处理

    • 可以考虑添加对 FileUtils::processLength() 返回值的检查,确保处理成功。
  3. 代码复用

    • 可以考虑将后缀处理逻辑提取为独立的辅助方法,提高代码复用性。
  4. 命名规范

    • 变量名 isCancele 存在拼写错误,应为 isCanceled

总体而言,这段代码的改进主要集中在提高用户体验(保留后缀名)、优化性能和增强安全性方面。新代码的逻辑更加清晰,处理方式更加合理,能够提供更好的文件重命名体验。

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 19, 2025

Reviewer's Guide

Refactors NameTextEdit to support dynamic max-length enforcement and cursor-aware truncation, introduces a setMaxLength API, and updates renameFile to reserve space for file suffixes while selecting only the base file name.

File-Level Changes

Change Details Files
Enhanced slotTextChanged to use dynamic limits and preserve cursor positioning
  • Removed naive text.chop loop
  • Captured raw cursor position and removed old length-based adjustments
  • Replaced hardcoded NAME_MAX with a computed limit in FileUtils::processLength
src/plugins/common/dfmplugin-propertydialog/views/editstackedwidget.cpp
Introduced setMaxLength API in NameTextEdit
  • Added setMaxLength method to clamp and store maxLengthVal
  • Declared maxLengthVal member in the header
src/plugins/common/dfmplugin-propertydialog/views/editstackedwidget.h
src/plugins/common/dfmplugin-propertydialog/views/editstackedwidget.cpp
Updated renameFile to reserve suffix length and select only the base name
  • Calculated reserve length from file suffix and passed it to setMaxLength
  • Enabled char count limit for long names where supported
  • Adjusted initial text selection to anchor only the base file name, preserving the suffix
src/plugins/common/dfmplugin-propertydialog/views/editstackedwidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dengzhongyuan365-dev dengzhongyuan365-dev marked this pull request as draft September 19, 2025 05:55
@dengzhongyuan365-dev dengzhongyuan365-dev force-pushed the master branch 2 times, most recently from a4b24ee to de26f98 Compare September 23, 2025 11:55
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 25, 2025

TAG Bot

New tag: 6.5.94
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3165

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 26, 2025

TAG Bot

New tag: 6.5.95
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3167

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 10, 2025

TAG Bot

New tag: 6.5.96
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3199

@dengzhongyuan365-dev dengzhongyuan365-dev force-pushed the master branch 2 times, most recently from df62b12 to 567f9d4 Compare October 15, 2025 05:30
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 16, 2025

TAG Bot

New tag: 6.5.97
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3224

…nagement

- Refactored the text input handling in the NameTextEdit class to improve cursor positioning and character limit enforcement.
- Introduced a new method `setMaxLength` to dynamically set the maximum length for text input based on file suffixes.
- Updated the renameFile method to reserve space for file suffixes, ensuring that the main file name is editable without truncating the suffix.

These changes enhance user experience by providing better control over text input and ensuring that file names are handled correctly.

bug: https://pms.uniontech.com/bug-view-321657.html
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 23, 2025

TAG Bot

New tag: 6.5.98
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3256

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 24, 2025

TAG Bot

New tag: 6.5.99
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3260

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 31, 2025

TAG Bot

New tag: 6.5.100
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3287

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 31, 2025

TAG Bot

New tag: 6.5.101
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3292

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 6, 2025

TAG Bot

New tag: 6.5.102
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3296

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 7, 2025

TAG Bot

New tag: 6.5.103
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3312

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 7, 2025

TAG Bot

New tag: 6.5.104
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3314

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 13, 2025

TAG Bot

New tag: 6.5.105
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3335

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 20, 2025

TAG Bot

New tag: 6.5.106
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3352

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