Skip to content

fix: text tooling unblock for ruby tags#61

Open
KirylHatalski wants to merge 2 commits intodevelopfrom
fix/AUT-4506/ruby-text-formating-fix
Open

fix: text tooling unblock for ruby tags#61
KirylHatalski wants to merge 2 commits intodevelopfrom
fix/AUT-4506/ruby-text-formating-fix

Conversation

@KirylHatalski
Copy link
Copy Markdown

@KirylHatalski KirylHatalski commented Apr 14, 2026

What is the purpose of this pull request?

https://oat-sa.atlassian.net/browse/AUT-4506

added whitelist for state less buttons for ruby tag text content

chrome_gecEh4Zk8P

Summary by CodeRabbit

  • Bug Fixes
    • Improved toolbar button state handling for ruby (furigana) annotations so buttons correctly reflect availability when creating, editing, or selecting ruby readings—reducing accidental actions and improving toolbar responsiveness.

@KirylHatalski KirylHatalski requested review from a team, Karol-Stelmaczonek, bartlomiejmarszal, pnal and tikhanovichA and removed request for a team April 14, 2026 15:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Walkthrough

Plugin adjusts toolbar command state logic for furigana (ruby) selections: it collects a subset of stateless toolbar buttons, detects when the selection is inside an rt child, and applies a 150ms-delayed transition that disables global toolbar state while forcing collected stateless buttons to TRISTATE_OFF after setting rubyFurigana to TRISTATE_ON.

Changes

Cohort / File(s) Summary
Furigana State Management
plugins/taofurigana/plugin.js
Added statelessButtonsList tracking and statelessButtons collection. Introduced isInRtFugirana() helper to detect selection within rt children. Modified refreshCommandState() to branch when selection is inside ruby: set rubyFurigana to TRISTATE_ON, and after 150ms call setButtonsState(TRISTATE_DISABLED) while forcing all collected stateless buttons to TRISTATE_OFF; retains existing delayed disable behavior when selection is inside rt.

Sequence Diagram(s)

sequenceDiagram
    participant Editor
    participant TaofuriganaPlugin
    participant Toolbar
    participant Buttons

    Editor->>TaofuriganaPlugin: selection change / refreshCommandState()
    TaofuriganaPlugin->>TaofuriganaPlugin: collect statelessButtons from toolbar
    TaofuriganaPlugin->>TaofuriganaPlugin: isInRuby? / isInRtFugirana?
    alt in ruby and deleteRubyIfNoRt() == false
        TaofuriganaPlugin->>Toolbar: set rubyFurigana = TRISTATE_ON
        Note right of TaofuriganaPlugin: start 150ms timeout
        par after 150ms
            TaofuriganaPlugin->>Toolbar: setButtonsState(TRISTATE_DISABLED)
            TaofuriganaPlugin->>Buttons: set each statelessButton -> TRISTATE_OFF
        end
    else in rt (or other cases)
        TaofuriganaPlugin->>Toolbar: set rubyFurigana = TRISTATE_ON
        Note right of TaofuriganaPlugin: existing delayed setButtonsState(TRISTATE_DISABLED)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: text tooling unblock for ruby tags' directly corresponds to the main change, which adds functionality to unblock text formatting tools for ruby tag content by implementing a whitelist for stateless buttons.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/AUT-4506/ruby-text-formating-fix

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@plugins/taofurigana/plugin.js`:
- Around line 96-101: The isInRtFugirana function incorrectly omits the
includeSelf flag when checking ancestors, so when the current node is the <rt>
element it returns false; update the call to node.getAscendant('rt') inside
isInRtFugirana to pass includeSelf: true (i.e., getAscendant('rt', {
includeSelf: true })) so the current <rt> node is counted as an ancestor and the
function correctly returns true for nodes that are the <rt> itself.
- Around line 223-229: The toolbar buttons are visually re-enabled but their
commands remain disabled because the code calls button.setState(...) instead of
updating the underlying command state; change the loop over statelessButtons
(where currently button.setState(CKEDITOR.TRISTATE_OFF)) to fetch each command
via editor.getCommand(button) and call .setState(CKEDITOR.TRISTATE_OFF) so both
UI and command states are reset; ensure this change is applied in the block
following setButtonsState(CKEDITOR.TRISTATE_DISABLED) and reference
setButtonsState, statelessButtons, button.setState, and
editor.getCommand(...).setState when locating the code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87f9a984-57d8-426f-b1f7-afd3588c82ee

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2b371 and ac25422.

📒 Files selected for processing (1)
  • plugins/taofurigana/plugin.js

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
plugins/taofurigana/plugin.js (1)

223-230: Track timeout IDs to prevent accumulation from rapid selection changes.

The mouseup and keyup listeners on lines 332-335 repeatedly call refreshCommandState(), which schedules two separate setTimeout calls on lines 225-230 and 233-235. Without tracking timeout IDs, rapid events can accumulate unresolved timeouts, causing a delayed timeout to fire after a newer state change, resulting in incorrect button states.

This pattern is used throughout the codebase (menu, notification, magicline, floatpanel, clipboard plugins). Add a plugin-level buttonStateTimeout variable and clear previous timeouts before scheduling new ones.

Proposed fix

Add variable declaration after line 11:

 		var statelessButtons = [];
+		var buttonStateTimeout;

Update both timeout blocks:

 					} else if (!isInRtFugirana(range.startContainer)) {
 						command.setState(CKEDITOR.TRISTATE_ON);
+						clearTimeout(buttonStateTimeout);
-						setTimeout(function () {
+						buttonStateTimeout = setTimeout(function () {
 							setButtonsState(CKEDITOR.TRISTATE_DISABLED);
 							statelessButtons.forEach(function (button) {
 								button.setState(CKEDITOR.TRISTATE_OFF);
 							});
 						}, 150);
 					} else {
 						command.setState(CKEDITOR.TRISTATE_ON);
+						clearTimeout(buttonStateTimeout);
-						setTimeout(function () {
+						buttonStateTimeout = setTimeout(function () {
 							setButtonsState(CKEDITOR.TRISTATE_DISABLED);
 						}, 150);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/taofurigana/plugin.js` around lines 223 - 230, Add a plugin-level
timeout tracker (e.g., buttonStateTimeout) and clear any existing timeout before
scheduling new ones in the blocks that call setTimeout from refreshCommandState;
specifically, declare buttonStateTimeout at plugin scope and in the blocks where
you call setTimeout to call clearTimeout(buttonStateTimeout) prior to assigning
buttonStateTimeout = setTimeout(...). Update both timeout usages that
setButtonsState(...) and update statelessButtons.forEach(...) so the previous
delayed handler is cancelled and only the latest timeout can fire.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plugins/taofurigana/plugin.js`:
- Around line 223-230: Add a plugin-level timeout tracker (e.g.,
buttonStateTimeout) and clear any existing timeout before scheduling new ones in
the blocks that call setTimeout from refreshCommandState; specifically, declare
buttonStateTimeout at plugin scope and in the blocks where you call setTimeout
to call clearTimeout(buttonStateTimeout) prior to assigning buttonStateTimeout =
setTimeout(...). Update both timeout usages that setButtonsState(...) and update
statelessButtons.forEach(...) so the previous delayed handler is cancelled and
only the latest timeout can fire.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c47ce7af-603f-49c8-a7b6-d59e8d6e248a

📥 Commits

Reviewing files that changed from the base of the PR and between ac25422 and c10cea0.

📒 Files selected for processing (1)
  • plugins/taofurigana/plugin.js

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