Skip to content

Commit

Permalink
toggle/untoggle format to continue typing in format/non-format
Browse files Browse the repository at this point in the history
  • Loading branch information
MAX-786 committed Aug 14, 2024
1 parent ad23bc8 commit ab500a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,11 @@ Additionally your frontend can
Note Hydra.js knows about the schema of your blocks and based on the field name will determine what to make your html editable.
Currently, Hydra.js supports BOLD, ITALIC & STRIKETHROUGH formats on slate blocks and following are the conditions when it breaks slate:
- if you select the whole text and change its formats your frontend might throw slate error saying `Cannot get the leaf node at path [0,0] because it refers to a non-leaf node: ` but it is due to proper syncing of json b/w hydrajs & adminUI.
- if you select text at the end of the line samething will happen.
IMPORTANT: Currently, Hydra.js supports BOLD, ITALIC & STRIKETHROUGH formats on slate blocks and following are the conditions when it breaks slate:
- if you select the whole text and change its formats your frontend might throw slate error saying `Cannot get the leaf node at path [0,0] because it refers to a non-leaf node:` but it is due to proper syncing of json b/w hydrajs & adminUI.
- At the endline if you press format button then it will change the state (active/inactive) but frontend might throw slate error/warning that `Error: Cannot find a descendant at path [0,4,0] in node:`
- pressing ENTER is not implemented so, pressing it will have abnormal changes & error ([TODO](https://github.com/collective/volto-hydra/issues/33))
These will not break the codebase completely as deserializer at the adminUI cleans up the html and make a proper
#### Inline media uploading ([TODO](https://github.com/collective/volto-hydra/issues/36))
Expand Down
11 changes: 5 additions & 6 deletions packages/hydra-js/hydra.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ class Bridge {
const handleSelectionChange = () => {
const selection = window.getSelection();
const range = selection.getRangeAt(0);
const selectedText = selection.toString();
console.log(selectedText);

// Append the bold button only if text is selected and the block has the data-editable-field="value" attribute

const formats = this.isFormatted(range);
Expand Down Expand Up @@ -576,7 +575,7 @@ class Bridge {

if (targetElement && this.isInlineEditing) {
this.handleTextChangeOnSlate(targetElement);
} else {
} else if (this.isInlineEditing) {
const targetElement = mutation.target?.parentElement.closest(
'[data-editable-field]',
);
Expand Down Expand Up @@ -762,7 +761,7 @@ class Bridge {

const range = selection.getRangeAt(0);
const currentFormats = this.isFormatted(range);
console.log(currentFormats);

if (currentFormats[format].present) {
this.unwrapFormatting(range, format);
} else {
Expand Down Expand Up @@ -790,7 +789,7 @@ class Bridge {
italic: ['EM', 'I'],
del: ['DEL'],
};

const selection = window.getSelection();
// Check if the selection is entirely within a formatting element of the specified type
let container = range.commonAncestorContainer;
while (
Expand All @@ -804,7 +803,7 @@ class Bridge {
range.startOffset === 0 &&
range.endOffset === container.textContent.length;

if (isEntireContentSelected) {
if (isEntireContentSelected || selection.isCollapsed) {
// Unwrap the entire element
this.unwrapElement(container);
} else {
Expand Down

0 comments on commit ab500a4

Please sign in to comment.