Skip to content

Commit

Permalink
Merge pull request #52 from oat-sa/fix/INF-279/ruby-tags-focus-and-na…
Browse files Browse the repository at this point in the history
…vigation

fix: ruby tags focus and navigation
  • Loading branch information
viktar-dzmitryieu-tao authored Jan 21, 2025
2 parents c11f67d + f98be7f commit d44c6ba
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions plugins/taofurigana/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ CKEDITOR.plugins.add('taofurigana', {
}
editor.fire( 'unlockSnapshot' );
return true;
}
}
}
/**
* Change command state according to the current selection content
Expand Down Expand Up @@ -181,7 +181,7 @@ CKEDITOR.plugins.add('taofurigana', {
setTimeout(function() {
setButtonsState(CKEDITOR.TRISTATE_DISABLED);
}, 150);

}
} else {
command.setState(CKEDITOR.TRISTATE_DISABLED);
Expand All @@ -199,14 +199,15 @@ CKEDITOR.plugins.add('taofurigana', {
rbElement,
rtElement,
range,
zeroWidthSpace,
emptyElement;
if (isInFugirana(startNode)) {
rubyElement = startNode.getAscendant('ruby');
rbElement = rubyElement.find('rb');
rtElement = rubyElement.find('rt');
if (deleteRubyIfNoRt(startNode, true)) {
refreshCommandState(editor);
} else if (rbElement.$.length && rtElement.$.length && startNode.getParent().$ === rtElement.$[0] &&
} else if (rbElement.$.length && rtElement.$.length && startNode.getParent().$ === rtElement.$[0] &&
startNode.$.nextSibling === null && curRange.endOffset + 1 >= startNode.$.length) {
// if in the end of rt text
// move cursor outside ruby element
Expand Down Expand Up @@ -235,15 +236,27 @@ CKEDITOR.plugins.add('taofurigana', {
rubyElement.append(rbElement);
rubyElement.append(rtElement);

// create a temporary element for binding the cursor
anchor = new CKEDITOR.dom.element('span', editor.document);
rtElement.append(anchor);
rtElement.appendHtml(' ');

editor.insertElement(rubyElement);
// add a zero-width space for the better navigation in Chrome (version >= 128) to the next sibling
zeroWidthSpace = new CKEDITOR.dom.text('\u200b', editor.document);
rubyElement.append(zeroWidthSpace);

// move cursor inside <rt>^</rt> Element
// move cursor inside the anchor
range = new CKEDITOR.dom.range(editor.document);
range.moveToElementEditablePosition(rtElement);
range.setStart(anchor, 0);
range.collapse(true);
editor.getSelection().removeAllRanges();
editor.getSelection().selectRanges([range]);
refreshCommandState(editor);

editor.fire( 'unlockSnapshot' );
// remove anchor
anchor.remove();
}
}
});
Expand Down

0 comments on commit d44c6ba

Please sign in to comment.